• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Python String Quiz

Question 1

Question 1: What is the output of the following program? Python3
str1 = \'{2}, {1} and {0}\'.format(\'a\', \'b\', \'c\') 
str2 = \'{0}{1}{0}\'.format(\'abra\', \'cad\') 
print(str1, str2) 
  • c, b and a abracad0
  • a, b and c abracadabra
  • a, b and c abracadcad
  • c, b and a abracadabra

Question 2

Question 2: What is the output of the following program? Python3
a = 2
b = \'3.77\'
c = -8
str1 = \'{0:.4f} {0:3d} {2} {1}\'.format(a, b, c) 
print(str1) 
  • 2.0000 2 -8 3.77
  • 2 3.77 -8 3.77
  • 2.000 3 -8 3.77
  • 2.000 2 8 3.77

Question 3

Question 3: What is the output of the following program? Python3
line = \"I\'ll come by then.\"
eline = \"\" 
for i in line: 
	eline += chr(ord(i)+3) 
print(eline)	 
  • L*oo frph e| wkhq1
  • L*oo#frph#e|#wkhq1
  • l*oo@frph@e|$wkhq1
  • O*oo#Frph#E|#wKhq1

Question 4

Question 4: What is the output of the following program? Python3
line = \"What will have so will\"
L = line.split(\'a\') 
for i in L: 
	print(i, end=\' \') 
  • [‘What’, ‘will’, ‘have’, ‘so’, ‘will’]
  • Wh t will h ve so will
  • What will have so will
  • [‘Wh’, ‘t will h’, ‘ve so will’]

Question 5

Question 5: What is the output of the following program? Python3
import string

Line1 = \"And Then There Were None\"
Line2 = \"Famous In Love\"
Line3 = \"Famous Were The Kol And Klaus\"
Line4 = Line1 + Line2 + Line3
print(\"And\" in Line4)
  • True 2
  • True
  • False
  • False 2

Question 6

Question 6: What is the output of the following program? Python3
my_string = \"geeksforgeeks\"
i = \"i\"
while i in my_string: 
	print(i, end =\" \") 
  • geeksforgeeks
  • No Output
  • i i i i i i …
  • g e e k s f o r g e e k s

Question 7

Question 7: What is the output of the following program? Python3
my_string = \'geeksforgeeks\'
for i in range(my_string): 
	print(i) 
  • 0 1 2 3 … 12
  • geeksforgeeks
  • No Output
  • Error

Question 8

Question 8: What is the output of the following program? Python3
my_string = \'geeksforgeeks\'
for i in range(len(my_string)): 
	my_string[i].upper() 
print (my_string) 
  • GEEKSFORGEEKS
  • geeksforgeeks
  • Error
  • No Output

Question 9

Question 9: What is the output of the following program? Python3
my_string = \'geeksforgeeks\'
for i in range(len(my_string)): 
	print (my_string, end=\" \") 
	my_string = \'a\'
  • aaaaaaaaaaaa
  • geeksforgeeks a a a a a a a a a a a a
  • Error
  • No Output

Question 10

Question 10: What is the output of the following program? Python3
x = 123
for i in x: 
	print(i, end=\" \") 
  • 1 2 3
  • 1 1 1
  • Error
  • No Output

There are 21 questions to complete.

Last Updated :
Take a part in the ongoing discussion