Python MCQs on Data Type: SET 1

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

a) Class

b) Dictionary

c) Tuples

d) List

Check Answer

Answer: A
Explanation: Class is not a core data type. It is a user defined data type.

 

2. Given a function that does not return any value, What value is thrown by default when executed in shell.

a) int

b) bool

c) void

d) None

Check Answer

Answer: d
Explanation: Python shell throws a NoneType object back.

 

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

>>>str=”hello”

>>>str[:3]

>>>

a) llo

b) hel

c) olleh

d) hello

Check Answer
Answer: b
Explanation: We are printing only the 1st three bytes of string.

 

4. Which of the following will run without errors?

a) round()

b) round(1372.888,4,7)

c) round(88.8)

d) round(4766.453,1,2)

Check Answer
Answer: c
Explanation: Execute help(round) in the shell to get details of the parameters that are passed into the round function.

 

5. What is the return type of function id?

a) bool

b) float

c) int

d) dict

Check Answer

Answer: c
Explanation: Execute help(id) to find out details in python shell.id returns a integer value that is unique.

 

6. In python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed.

>>x = 17 ? 2

objective is to make sure x has a integer value, select all that apply (python 3.xx)

a) x = 17 // 2

b) x = int(17 / 2)

c) x = 17 % 2

d) All of the mentioned

Check Answer

Answer: d
Explanation: // is integer operation in python 3.0 and int(..) is a type cast operator.

 

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

car = bus

a) SyntaxError

b) TypeError

c) ValueError

d) NameError

Check Answer

Answer: d
Explanation: bus is not defined hence name error.

 

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

def demo(x):

x = x + ‘2’

x = x*2

return x

>>>demo(“text”)

a) indentation Error

b) cannot perform mathematical operation on strings

c) text2

d) text2text2

Check Answer

Answer: a
Explanation: Python codes have to be indented properly.

 

9. What data type is the object below?

L = [1, 23, ‘hello’, 1]

a) dictionary

b) list

c) array

d) tuple

Check Answer

Answer: b
Explanation: List data type can store any values within it

 

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

Check Answer

Answer: d
Explanation: Dictionary stores values in terms of keys and values.

 

Page  1  2  3

Leave a Comment