Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Python-Quizzes | Python String Quiz | Question 2

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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




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

(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
Last Updated : 18 Sep, 2020
Like Article
Save Article
Similar Reads