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

8/8

Page

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

What is the default value of encoding in encode()?

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('{:$}'.format(1112223334))

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('ab12'.isalnum())

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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"))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('ab\ncd\nef'.splitlines())

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('xyyzxxyxyy'.lstrip('xyy'))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('abc'.encode())

Select an option to see the answer and solution.

What will be the output of the following Python code?
class tester:
    def __init__(self, id):
        self.id = str(id)
        id="224"
 
>>>temp = tester(12)
>>>print(temp.id)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('cba'.maketrans('abc', '123'))

Select an option to see the answer and solution.