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

5/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?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

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('*', "abcde".center(6), '*', sep='')

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
print('a B'.isalpha())

Select an option to see the answer and solution.

What function do you use to read a string?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
print('Ab!2'.swapcase())

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
class Name:
    def __init__(self, firstName, mi, lastName):
        self.firstName = firstName
        self.mi = mi
        self.lastName = lastName
 
firstName = "John"
name = Name(firstName, 'F', "Smith")
firstName = "Peter"
name.lastName = "Pan"
print(name.firstName, name.lastName)

Select an option to see the answer and solution.

What will be displayed by print(ord('b') - ord('a'))?

Select an option to see the answer and solution.

What will be the output of the following Python code?
print("xyyzxyzxzxyy".endswith("xyy"))

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} and {1} is {2}'.format(2, 10, 12))

Select an option to see the answer and solution.