Python MCQ Quiz Hub

Python Mcq Set 5

Choose a topic to test your knowledge and improve your Python skills

What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i)





✅ Correct Answer: 1

What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i) for i in x: print(i)





✅ Correct Answer: 1

What will be the output of the following Python code? string = "my name is x" for i in string: print (i, end=", ")





✅ Correct Answer: 1

What will be the output of the following Python code? string = "my name is x" for i in string.split(): print (i, end=", ")





✅ Correct Answer: 3

What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[-1] in a: print(a[-1])





✅ Correct Answer: 2

What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[0] in a: print(a[0])





✅ Correct Answer: 1

What will be the output of the following Python code snippet? a = [0, 1, 2, 3] i = -2 for i not in a: print(i) i += 1





✅ Correct Answer: 3

What will be the output of the following Python code snippet? string = "my name is x" for i in ' '.join(string.split()): print (i, end=", ")





✅ Correct Answer: 1

What will be the output of the following Python code? for i in range(10): if i == 5: break else: print(i) else: print("Here")





✅ Correct Answer: 3

What will be the output of the following Python statement? >>>"a"+"bc"





✅ Correct Answer: 4

What will be the output of the following Python statement? >>>"abcd"[2:]





✅ Correct Answer: 3

The output of executing string.ascii_letters can also be achieved by:





✅ Correct Answer: 2

What will be the output of the following Python code? >>> str1 = 'hello' >>> str2 = ',' >>> str3 = 'world' >>> str1[-1:]





✅ Correct Answer: 4

What arithmetic operators cannot be used with strings?





✅ Correct Answer: 3

What will be the output of the following Python code? >>>print (r" hello")





✅ Correct Answer: 2

What will be the output of the following Python statement? >>>print('new' 'line')





✅ Correct Answer: 3

What will be the output of the following Python code? >>>str1="helloworld" >>>str1[::-1]





✅ Correct Answer: 1

What will be the output of the following Python code? print(0xA + 0xB + 0xC)





✅ Correct Answer: 4

What will be the output of the following Python code? >>>example = "snow world" >>>print("%s" % example[4:7])





✅ Correct Answer: 1

What will be the output of the following Python code? >>>example = "snow world" >>>example[3] = 's' >>>print example





✅ Correct Answer: 3

What will be the output of the following Python code? >>>max("what are you")





✅ Correct Answer: 4

Given a string example=”hello” what is the output of example.count(‘l’)?





✅ Correct Answer: 1

What will be the output of the following Python code? >>>example = "helle" >>>example.find("e")





✅ Correct Answer: 3

What will be the output of the following Python code? >>>example = "helle" >>>example.rfind("e")





✅ Correct Answer: 2

What will be the output of the following Python code? >>>example="helloworld" >>>example[::-1].startswith("d")





✅ Correct Answer: 2

To concatenate two strings to a third what statements are applicable?





✅ Correct Answer: 3

What will be the output of the following Python statement? >>>chr(ord('A'))





✅ Correct Answer: 1

What will be the output of the following Python statement? >>>print(chr(ord('b')+1))





✅ Correct Answer: 3

Which of the following statement prints helloexample est.txt?





✅ Correct Answer: 2

Suppose s is “ World ”, what is s.strip()?





✅ Correct Answer: 4

The format function, when applied on a string returns ______





✅ Correct Answer: 4

What will be the output of the “hello” +1+2+3?





✅ Correct Answer: 3

What will be the output of the following Python code? >>>print("D", end = ' ') >>>print("C", end = ' ') >>>print("B", end = ' ') >>>print("A", end = ' ')





✅ Correct Answer: 3

What will be the output of the following Python statement?(python 3.xx) >>>print(format("Welcome", "10s"), end = '#') >>>print(format(111, "4d"), end = '#') >>>print(format(924.656, "3.2f"))





✅ Correct Answer: 4

What will be displayed by print(ord(‘b’) – ord(‘a’))?





✅ Correct Answer: 2

Say s=”hello” what will be the return value of type(s)?





✅ Correct Answer: 3

What is “Hello”.replace(“l”, “e”)?





✅ Correct Answer: 1

To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?





✅ Correct Answer: 3

To return the length of string s what command do we execute?





✅ Correct Answer: 1

If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.





✅ Correct Answer: 4

To check whether string s1 contains another string s2, use ____





✅ Correct Answer: 1

Suppose i is 5 and j is 4, i + j is same as ________





✅ Correct Answer: 2

What function do you use to read a string?





✅ Correct Answer: 1

Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).





✅ Correct Answer: 2

What will be the output of the following Python code? print("abc DEF".capitalize())





✅ Correct Answer: 3

What will be the output of the following Python code? print("abc. DEF".capitalize())





✅ Correct Answer: 3

What will be the output of the following Python code? print("abcdef".center())





✅ Correct Answer: 3

What will be the output of the following Python code? print("abcdef".center(0))





✅ Correct Answer: 2

What will be the output of the following Python code? print('*', "abcdef".center(7), '*')





✅ Correct Answer: 2

What will be the output of the following Python code? print('*', "abcdef".center(7), '*', sep='')





✅ Correct Answer: 4