Python-Quizzes | Python String Quiz | Question 2

Question 2: What is the output of the following program?

filter_none

edit
close

play_arrow

link
brightness_4
code

a = 2
b = '3.77'
c = -8
str1 = '{0:.4f} {0:3d} {2} {1}'.format(a, b, c) 
print(str1) 

chevron_right


(A) 2.0000 2 -8 3.77
(B) 2 3.77 -8 3.77
(C) 2.000 3 -8 3.77
(D) 2.000 2 8 3.77


Answer: (A)

Explanation: At Index 0, integer a is formatted into a float with 4 decimal points, thus 2.0000. At Index 0, a = 2 is formatted into an integer, thus it remains to 2. Index 2 and 1 values are picked next, which are -8 and 3.77 respectively.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.