Python Programming (2180711) MCQs

MCQs of Structured Types, Mutability and Higher-Order Functions

Showing 1 to 10 out of 48 Questions
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
Answer:

Option (b)

2.
What will be the output of the following Python statement?
>>>"a"+"bc"
(a) a
(b) bc
(c) bca
(d) abc
Answer:

Option (d)

3.
What will be the output of the following Python statement?
>>>"abcd"[2:]
(a) a
(b) ab
(c) cd
(d) dc
Answer:

Option (c)

4.
What arithmetic operators cannot be used with strings?
(a) +
(b) *
(c) -
(d) All of the mentioned
Answer:

Option (c)

5.
What will be the output of the following Python statement?
>>>print('new' 'line')
(a) Error
(b) Output equivalent to print ‘new\nline’
(c) newline
(d) new line
Answer:

Option (c)

6.
What will be 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
Answer:

Option (d)

7.
Suppose s is “\t\tWorld\n”, what is s.strip()?
(a) \t\tWorld\n
(b) \t\tWorld\n
(c) \t\tWORLD\n
(d) World
Answer:

Option (d)

8.
Which of the following statement prints hello\example\test.txt?
(a) print(“hello\example\test.txt”)
(b) print(“hello\\example\\test.txt”)
(c) print(“hello\”example\”test.txt”)
(d) print(“hello”\example”\test.txt”)
Answer:

Option (b)

9.
The format function, when applied on a string returns ___________
(a) Error
(b) int
(c) bool
(d) str
Answer:

Option (d)

10.
What will be displayed by print(ord(‘b’) – ord(‘a’))?
(a) 0
(b) 1
(c) -1
(d) 2
Answer:

Option (b)

Showing 1 to 10 out of 48 Questions