Python Strings: Python Language Strings MCQs

Python Strings. Part 2 of Multiple Choice Questions in Python related to Strings. For more Python topics see Python MCQs

 

Python Strings

 

 

The output of executing string.ascii_letters can also be achieved by ??

a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_uppercase
c) string.letters
d) string.lowercase_string.uppercase

 

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)

a) 224
b) Error
c) 12
d) None

 

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

>>>”abcd”[2:]

a) a
b) ab
c) cd
d) dc

 

What is the output of the following Python code ??

class father:
def __init__(self, param):
self.o1 = param

class child(father):
def __init__(self, param):
self.o2 = param

>>>obj = child(22)
>>>print “%d %d” % (obj.o1, obj.o2)

a) None None
b) None 22
c) 22 None
d) Error is generated

 

Python Strings

 

What is the output ??

>>>”a”+”bc”

a) a
b) bc
c) bca
d) abc

 

Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space) ??

a) __345.355
b) ___345.355
c) ____345.355
d) _____345.354

 

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

a) int
b) bool
c) str
d) String

 

What function do you use to read a string ??

a) input(“Enter a string”)
b) eval(input(“Enter a string”))
c) enter(“Enter a string”)
d) eval(enter(“Enter a string”))

 

Python Strings

 

What will be displayed by print(ord(‘b’) – ord(‘a’)) ??

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

 

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)

a) Peter Pan
b) John Pan
c) Peter Smith
d) John Smith

 

What would 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”))

a) Welcome# 111#924.66
b) Welcome#111#924.66
c) Welcome#111#.66
d) Welcome # 111#924.66

 

What will be the output of the following code ??

class Count:
def __init__(self, count = 0):
self.__count = count

c1 = Count(2)
c2 = Count(2)

print(id(c1) == id(c2), end = ” “)

s1 = “Good”
s2 = “Good”

print(id(s1) == id(s2))

a) True False
b) True True
c) False True
d) False False

 

Python Strings

 

What is the output of the code ??

>>>print(“D”, end = ‘ ‘)
>>>print(“C”, end = ‘ ‘)
>>>print(“B”, end = ‘ ‘)
>>>print(“A”, end = ‘ ‘)

a) DCBA
b) A, B, C, D
c) D C B A
d) D, C, B, A will be displayed on four lines

 

Suppose i is 5 and j is 4, i + j is same as ??

a) i.__add(j)
b) i.__add__(j)
c) i.__Add(j)
d) i.__ADD(j)

 

What will be the output of the “hello” +1+2+3 ??

a) hello123
b) hello
c) Error
d) hello6

Leave a Comment

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

error: Content is protected !!