Q30
What will be the output of the following Python function? float(' -12345 ') (Note that the number of blank spaces before the number is 5)
A.
-12345.0 (5 blank spaces before the number)
B.
-12345.0
AnswerC.
Error
D.
-12345.000000000.... (infinite decimal places)
Answer: Option B
Solution
Answer: Option B
Solution:
The correct answer is Option B: -12345.0.The float() function in Python is used to convert a string or a number to a floating-point number. When you pass the string ' -12345\n' (which includes leading and trailing whitespace characters) to the float() function, it strips the leading and trailing whitespace and converts the remaining characters to a floating-point number. In this case, it converts '-12345' to a float, resulting in -12345.0.