Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Python MCQ 2

1. Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class

Answer:

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

>>> str = “Hello”


>>> str [ : 2 ]
>>>

a) he
b) lo
c) olleh
d) hello

Answer:

3. What is the return type of function id?


a) int
b) float
c) bool
d) dict

Answer:

4. What error occurs when you execute the following Python code snippet?

apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError

Answer:

5. What data type is the object below?

L = [ 1, 23, ‘hello’,1]
a) list
b) dictionary
c) array
d) tuple

Answer:

6. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary

Answer:

7. Which of the following results in a SyntaxError?


a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’

Answer:

8. What is the average value of the following Python code snippet?

>>> grade1 = 80
>>>grade2 = 90

>>>average = ( grade1 + grade2 ) / 2

a) 85.0
b) 85.1
c) 95.0
d) 95.1

Answer:

9. Select all options that print.

hello-how-are-you

a) print(‘hello’, ‘how’, ‘are’, ‘you’)


b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)

Answer:

10. What is the return value of trunc()?


a) int
b) bool
c) float
d) None

Answer:

11. What will be the output of the following Python code snippet?

'%d %s %g you' %(1, 'hello', 4.0)

a) Error
b) 1 hello you 4.0
c) 1 hello 4 you
d) 1 4 hello you

Answer:

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

x = ['ab', 'cd']
for i in x:
i.upper()
print(x)

a) [‘ab’, ‘cd’]
b) [‘AB’, ‘CD’]
c) [None, None]
d) none of the mentioned

Answer:

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

x = "abcdef"
i = "a"
while i in x:
x = x[1:]
print(i, end = " ")

a) a a a a a a
b) a
c) no output
d) error

Answer:

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

for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")

a) 0 1 2 3 4 Here
b) 0 1 2 3 4 5 Here
c) 0 1 2 3 4
d) 1 2 3 4 5

Answer:
15. What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
for a[-1] in a:
print(a[-1])

a) 0 1 2 3
b) 0 1 2 2
c) 3 3 3 3
d) error

Answer:

16. What will be the output of the following Python code snippet?

string = "my name is x"


for i in ' '.join(string.split()):
print (i, end=", ")

a) m, y, , n, a, m, e, , i, s, , x,
b) m, y, , n, a, m, e, , i, s, , x
c) my, name, is, x,
d) error

Answer:

17. What will be the output of the following Python statement?

>>>"a"+"bc"

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

Answer:
18. 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

Answer:

19. 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: c
.

20. 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

Answer:

21. What will be the output of the following Python statement?

>>>chr(ord('A'))

a) A
b) B
c) a
d) Error

Answer:

22. 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:

23. The format function, when applied on a string returns ___________


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

Answer:

24. What is “Hello”.replace(“l”, “e”)?


a) Heeeo
b) Heelo
c) Heleo
d) None
Answer:
.l

25. To return the length of string s what command do we execute?


a) s.__len__()
b) len(s)
c) size(s)
d) s.size()

Answer:

You might also like