LearnFrenzy
Sign in Take a free test

Python Built-in Functions · Predict the Output · Question 15

Converting strings Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

What is the output of the following Python program?

main.py
print(int("  42\n"), float(" 3.5 "), int("0x1f", 16), bool("0"), bool(int("0")))
  • A 42 3.5 31 False False
  • B ValueError
  • C 42 3.5 1f True False
  • D 42 3.5 31 True False Correct
Correct Answer: Option D

int and float ignore surrounding whitespace. "0" is a non-empty string (truthy); int("0") is 0 (falsy).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links