Friday , September 20 2024

The following code: print(float(“1, 3”))

Questions BankCategory: Python Essentials 2The following code: print(float(“1, 3”))
The following code:

print(float("1, 3"))
  • prints 1.3
  • prints 13
  • prints 1,3
  • raises a ValueError exception

Explanation: The float function tries to convert the 1, 3 string into a floating-point value. Since it contains a comma and a whitespace, a ValueError exception is raised because it cannot be converted.

More Questions: Python Essentials 2 – Module 2 Test