What will be the output of the following Python code? [code]'%s' %((1.23,),)[/code]

What will be the output of the following Python code?
Code:
'%s' %((1.23,),)
A. ‘(1.23,)’
B. 1.23,
C. (,1.23)
D. ‘1.23’
 
Answer: a
Explanation: The formatting expression accepts either a single substitution value, or a tuple of one or more items. Since single item can be given either by itself or within the tuple, a tuple to be formatted must be provided as a tested tuple. Hence the output of the code is: >>> ‘%s’ %((1.23,),).
 

Tìm kiếm

Back
Top