Open In App

Python-Quizzes | Python String Quiz | Question 1

Like Article
Like
Save
Share
Report

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




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


(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


Last Updated : 18 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads