What will be the output of the following Python statement?(python 3.xx)
a) Welcome# 111#924.66
b) Welcome#111#924.66
c) Welcome#111#.66
d) Welcome # 111#924.66
Explanation: Execute in the shell to verify.
What will be displayed by print(ord(‘b’) – ord(‘a’))?
a) 0
b) 1
c) -1
d) 2
Explanation: ASCII value of b is one more than a. Hence the output of this code is 98-97, which is equal to 1.
Say s=”hello” what will be the return value of type(s)?
a) int
b) bool
c) str
d) String
Explanation: str is used to represent strings in python.
What is “Hello”.replace(“l”, “e”)?
a) Heeeo
b) Heelo
c) Heleo
d) None
Explanation: Execute in shell to verify.
To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
a) s[]
b) s.getitem(3)
c) s.__getitem__(3)
d) s.getItem(3)
Explanation: __getitem(..) can be used to get character at index specified as parameter.
To return the length of string s what command do we execute?
a) s.__len__()
b) len(s)
c) size(s)
d) s.size()
Explanation: Execute in shell to verify.