Practice mode Python

What happens when int(“3.5”) is evaluated in Python?

Correct answer A. A ValueError is raised

Explanation

int() can parse a string only if it represents an integer literal, so the decimal point makes "3.5" invalid and a ValueError is raised. int(3.5) with a float does work and truncates to 3. To convert the string, use int(float("3.5")).

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.