Variables, Types & Operators · Question 14 · Medium

A string holding a decimal number is passed straight to int(). What is the result?

print(int("3.7"))
  1. 3
  2. 4
  3. TypeError
  4. ValueError
Answer and explanation

Answer: D. ValueError

Explanation: int() accepts a string only if it looks like a whole number, so "3.7" raises ValueError. int(3.7) on a float would give 3, and int(float("3.7")) is the way to convert this string.

Previous: Python 3's round() is called on two values that end in .5. What does this print? · Next: Which statement about the operators == and is is correct?

Practise variables, types & operators

Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.

More variables, types & operators questions

More python practice

Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge