Question 1
Q1A developer is writing a script to process sensor data. The script receives a hexadecimal string representing a temperature reading, such as '0x1A'. The goal is to convert this string into its decimal integer equivalent. Which line of code correctly performs this conversion?
Show answer & explanation
Correct answer: A
The int() function can take a second argument for the base. When the base is set to 0, Python automatically infers the base from the string's prefix. '0x' indicates hexadecimal (base 16), '0o' indicates octal (base 8), and '0b' indicates binary (base 2). This is the most robust way to handle prefixed numeral strings.