Strings in Python: Python Language Strings MCQs

Strings in Python. Multiple Choice Questions on Strings in Python Programming language for tests and interview preparations. For all related topics see Python MCQs

 

Strings in Python

 

 

To concatenate two strings to a third what statements are applicable ??

a) s3 = s1 . s2
b) s3 = s1.add(s2)
c) s3 = s1.__add__(s2)
d) s3 = s1 * s2

 

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

print(0xA + 0xB + 0xC)

a) 0xA0xB0xC
b) Error
c) 0x22
d) 33

 

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

>>>example=”helloworld”
>>>example[::-1].startswith(“d”)

a) dlrowolleh
b) True
c) -1
d) None

 

What will be the output of following python code ??

>>>str1=”helloworld”
>>>str1[::-1]

a) dlrowolleh
b) hello
c) world
d) helloworld

 

Strings in Python

 

What will be output of the following python code ??

>>>example = “helle”
>>>example.rfind(“e”)

a) -1
b) 4
c) 3
d) 1

 

What will the output of the following python code ??

>>> print(‘x\97\x98’)

a) Error
b) 97
98
c) x\97
d) \x97\x98

 

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

>>>example = “helle”
>>>example.find(“e”)

a) Error
b) -1
c) 1
d) 0

 

What will be the output of the following python ??

>>>print(‘new’ ‘line’)

a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line

 

Strings in Python

 

Given a string example=”hello” what is the output of example.count(‘l’) ??

a) 2
b) 1
c) None
d) 0

 

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

>>>print (r”\nhello”)

a) a new line and hello
b) \nhello
c) the letter r and then hello
d) error

 

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

>>>max(“what are you”)

a) error
b) u
c) t
d) y

 

What arithmetic operators cannot be used with strings ??

a) +
b) *
c) –
d) All of the mentioned

 

Strings in Python

 

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

>>>example = “snow world”
>>>example[3] = ‘s’
>>>print example

a) snow
b) snow world
c) Error
d) snos world

 

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

>>> str1 = ‘hello’
>>> str2 = ‘,’
>>> str3 = ‘world’
>>> str1[-1:]

a) olleh
b) hello
c) h
d) o

 

What will be the output of the following code in python ??

>>>example = “snow world”
>>>print(“%s” % example[4:7])

a) wo
b) world
c) sn
d) rl

Leave a Comment

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

error: Content is protected !!