Exam-style question
Try this first
In Python 3, which expression converts the string "42" into an integer?.
- A.str("42")
- B.float("42")
- C.int("42")
- D.chr("42")
Answer and explanation
Concise answer
int("42")
Why this is correct
int converts a suitable string representation of a whole number into an integer. str performs conversion to a string, float produces a floating-point value, and chr requires a character code integer.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
