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

6/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?
print("xyyzxyzxzxyy".count('yy'))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('ab'.zfill(5))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('abcefd'.replace('cd', '12'))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Suppose s is “\t\tWorld\n”, what is s.strip()?

Select an option to see the answer and solution.

What will be the output of the following Python code?
class father:
    def __init__(self, param):
        self.o1 = param
 
class child(father):
    def __init__(self, param):
        self.o2 = param
 
>>>obj = child(22)
>>>print "%d %d" % (obj.o1, obj.o2)

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('The sum of {0:b} and {1:x} is {2:o}'.format(2, 10, 12))

Select an option to see the answer and solution.

What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 1))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.