Vidyalelo
Python · all questions

MCQs for Python Strings: Exam
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

160

Questions

7/8

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Python code snippet?
print('Hello World'.istitle())

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('abcdefcdghcd'.split('cd', -1))

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('abcd'.partition('cd'))

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('ab cd-ef'.title())

Select an option to see the answer and solution.

What will be the output of the following Python code?
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python statement?
>>> print('x\97\x98')

Select an option to see the answer and solution.

What is "Hello".replace("l", "e")?

Select an option to see the answer and solution.

Given a string example="hello" what is the output of example.count('l')?

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('abcd'.translate({97: 98, 98: 99, 99: 100}))

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('ab cd ef'.title())

Select an option to see the answer and solution.

What will be the output of the following Python code?
class Count:
    def __init__(self, count = 0):
       self.__count = count
 
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
 
s1 = "Good"
s2 = "Good"
print(id(s1) == id(s2))

Select an option to see the answer and solution.

What will be the output of the following Python code?
print("ab\tcd\tef".expandtabs(4))

Select an option to see the answer and solution.

What will be the output of the following Python code?
print("Hello {0!r} and {0!s}".format('foo', 'bin'))

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('Hello!2@#World'.istitle())

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('abef'.partition('cd'))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('11'.isnumeric())

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('HelloWorld'.istitle())

Select an option to see the answer and solution.