Python Strings Interview Test: Python MCQs

Python Strings Interview Test. MCQs related to Strings in Python for Interviews and tests preparations. For more String related MCQs visit Python Multiple Choice Questions

 

Python Strings Interview Test

 

 

What will be the output of the following Python code ??

print(‘abcdef’.partition(‘cd’))

a) (‘ab’, ‘ef’)
b) (‘abef’)
c) (‘ab’, ‘cd’, ‘ef’)
d) 2

 

What will be the output of the following Python code snippet ??

print(‘ab’.zfill(5))

a) 000ab
b) 00ab0
c) 0ab00
d) ab000

 

What will be the output of the following ??

print(‘xyyxyyxyxyxxy’.replace(‘xy’, ’12’, 100))

a) xyyxyyxyxyxxy
b) 12y12y1212x12
c) none of the mentioned
d) error

 

What will be the output of the following ??

print(‘abcd’.translate({‘a’: ‘1’, ‘b’: ‘2’, ‘c’: ‘3’, ‘d’: ‘4’}))

a) abcd
b) 1234
c) error
d) none of the mentioned

 

Python Strings Interview Test

 

What will be the output of the following ??

print(‘a’.maketrans(‘ABC’, ‘123’))

a) {97: 49, 98: 50, 99: 51}
b) {65: 49, 66: 50, 67: 51}
c) {97: 49}
d) 1

 

What will be the output of the expression ??

print(‘abcd’.translate({97: 98, 98: 99, 99: 100}))

a) bcde
b) abcd
c) error
d) none of the mentioned

 

What will be the output of the following Python statement ??

print(‘xyyxyyxyxyxxy’.replace(‘xy’, ’12’, 0))

a) xyyxyyxyxyxxy
b) 12y12y1212x12
c) 12yxyyxyxyxxy
d) xyyxyyxyxyx12

 

What will be the output of the following code snippet ??

print(‘abcd’.translate(‘a’.maketrans(‘abc’, ‘bcd’)))

a) bcde
b) abcd
c) error
d) bcdd

 

Python Strings Interview Test

 

What will be the output of the following Python code ??

print(‘cba’.maketrans(‘abc’, ‘123’))

a) {97: 49, 98: 50, 99: 51}
b) {65: 49, 66: 50, 67: 51}
c) 321
d) 123

 

What will be the output of the following Python code snippet ??

print(‘ab cd-ef’.title())

a) Ab cd-ef
b) Ab Cd-ef
c) Ab Cd-Ef
d) None of the mentioned

 

What will be the output of the following Python code snippet ??

print(‘abcefd’.replace(‘cd’, ’12’))

a) ab1ef2
b) abcefd
c) ab1efd
d) ab12ed2

 

What will be the output ??

print(‘ab cd ef’.title())

a) Ab cd ef
b) Ab cd eF
c) Ab Cd Ef
d) None of the mentioned

 

Python Strings Interview Test

 

What will be the output of the following Python code ??

print(‘xyxxyyzxxy’.lstrip(‘xyy’))

a) zxxy
b) xyxxyyzxxy
c) xyxzxxy
d) none of the mentioned

 

What is the ouput of this ??

print(‘Ab!2’.swapcase())

a) AB!@
b) ab12
c) aB!2
d) aB1@

 

What will be the output of the following Python ??

print(‘abef’.replace(‘cd’, ’12’))

a) abef
b) 12
c) error
d) none of the mentioned

 

What will be the output of the following Python code ??

print(‘ab\ncd\nef’.splitlines())

a) [‘ab’, ‘cd’, ‘ef’]
b) [‘ab\n’, ‘cd\n’, ‘ef\n’]
c) [‘ab\n’, ‘cd\n’, ‘ef’]
d) [‘ab’, ‘cd’, ‘ef\n’]

 

Python Strings Interview Test

 

What will be the output of the following ??

print(‘xyyzxxyxyy’.lstrip(‘xyy’))

a) error
b) zxxyxyy
c) z
d) zxxy

 

What will be the output of the following Python code ??

print(‘abcdefcdghcd’.split(‘cd’, 2))

a) [‘ab’, ‘ef’, ‘ghcd’]
b) [‘ab’, ‘efcdghcd’]
c) [‘abcdef’, ‘ghcd’]
d) none of the mentioned

 

What will be the output of the following statement ??

print(‘abcdef12’.replace(‘cd’, ’12’))

a) ab12ef12
b) abcdef12
c) ab12efcd
d) none of the mentioned

 

What is the output ??

print(”’
\tfoo”’.lstrip())

a) \tfoo
b) foo
c)   foo
d) none of the mentioned

 

Python Strings Interview Test

 

What will be the output ??

print(‘abef’.partition(‘cd’))

a) (‘abef’)
b) (‘abef’, ‘cd’, ”)
c) (‘abef’, ”, ”)
d) error

 

What is the output ??

print(‘1Rn@’.lower())

a) n
b) 1rn@
c) rn
d) r

 

What will be the output of the following Python code snippet ??

print(‘cd’.partition(‘cd’))

a) (‘cd’)
b) (”)
c) (‘cd’, ”, ”)
d) (”, ‘cd’, ”)

 

What will be the output of the following Python code ??

print(‘Hello!2@#World’.istitle())

a) True
b) False
c) None
d) error

 

What will be the output of the following Python code snippet ??

print(‘+99’.zfill(5))

a) 00+99
b) 00099
c) +0099
d) +++99

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!