Python-Quizzes | Python String Quiz | Question 1

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

filter_none

edit
close

play_arrow

link
brightness_4
code

str1 = '{2}, {1} and {0}'.format('a', 'b', 'c'
str2 = '{0}{1}{0}'.format('abra', 'cad'
print(str1, str2) 

chevron_right


(A) c, b and a abracad0
(B) a, b and c abracadabra
(C) a, b and c abracadcad
(D) c, b and a abracadabra


Answer: (D)

Explanation: String function format takes a format string and an arbitrary set of positional and keyword arguments. For str1 ‘a’ has index 2, ‘b’ index 1 and ‘c’ index 0. str2 has only two indices 0 and 1. Index 0 is used twice at 1st and 3rd time.


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.