?
What will be the output of the following Python function?
What will be the output of the following Python function?
float(' -12345\n')
(Note that the number of blank spaces before the number is 5)
float(' -12345\n')
Answer & Solution
Correct Answer:
Option
B
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.
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.
Join the Discussion
Login to post a comment or share your explanation.
Login