PYTHON GTU MCQ (CH-3 Python Strings)
PYTHON
[SUBJECT CODE: 2180711]
CH-3 PYTHON STRINGS
1.The output of executing string.ascii_letters can also be
achieved by:
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase
2.What arithmetic operators cannot be used with
strings?
a) +
b) *
c) –
d) All of the mentioned
3.print(0xA + 0xB + 0xC):
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
4.What will be the output of the following Python code?
2. def __init__(self, param):
3. self.o1 = param
4.
5. class child(father):
6. def __init__(self, param):
7. self.o2 = param
8.
9. >>>obj = child(22)
a) None None
b) None 22
c) 22 None
d) Error is generated
5.What will be the output of the following Python
code?
a) -1
b) 4
c) 3
d) 1
6.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
a) print(“hello\example\test.txt”)
b) print(“hello\\example\\test.txt”)
c) print(“hello\”example\”test.txt”)
8.Suppose s is “\t\tWorld\n”, what is s.strip()?
a) \t\tWorld\n
b) \t\tWorld\n
c) \t\tWORLD\n
d) World
9.The format function, when applied on a string returns
___________
a) Error
b) int
c) bool
d) str
10.What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6
11.What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6
a) s.__len__()
b) len(s)
c) size(s)
13.If a class defines the __str__(self) method, for an object
obj for the class, you can use which command to invoke the
__str__ method.
a) obj.__str__()
b) str(obj)
c) print obj
d) all of the mentioned
14.To check whether string s1 contains another string s2, use
________
a) s1.__contains__(s2)
b) s2 in s1
c) s1.contains(s2)
d) si.in(s2)
15.What will be the output of the following Python code?
2. def __init__(self, count = 0):
3. self.__count = count
4.
5. c1 = Count(2)
6. c2 = Count(2)
7. print(id(c1) == id(c2), end = " ")
9. s1 = "Good"
10.s2 = "Good"
a) True False
b) True True
c) False True
d) False False
16.What will be the output of the following Python code?
2. def __init__(self, firstName, mi, lastName):
3. self.firstName = firstName
4. self.mi = mi
5. self.lastName = lastName
7. firstName = "John"
8. name = Name(firstName, 'F', "Smith")
9. firstName = "Peter"
10.name.lastName = "Pan"
a) Peter Pan
b) John Pan
c) Peter Smith
d) John Smith
a) input(“Enter a string”)
b) eval(input(“Enter a string”))
c) enter(“Enter a string”)
d) eval(enter(“Enter a string”))
18.What will be the output of the following Python code?
b) * abcdef *
c) *abcdef *
19.What will be the output of the following Python code?
b) * abcde *
c) *abcde *
20.What will be the output of the following Python code?
b) abcdef1
c) abcdef
21.What will be the output of the following Python code?
b) abcdef1212
c) 1212abcdef
22.What will be displayed by print(ord(‘b’) – ord(‘a’))?
a) 0
b) 1
c) -1
d) 2
23.What will be the output of the following Python code?
2. >>>print("C", end = ' ')
3. >>>print("B", end = ' ')
a) DCBA
b) A, B, C, D
c) D C B A
d) D, C, B, A will be displayed on four lines
24.What will be the output of the following Python code?
a) dlrowolleh
b) True
c) -1
d) None
25.What will be the output of the following Python code?
a) Error
b) -1
c) 1
d) 0




