MCQ

Python MCQ and Answers – Data types

This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Data types”.
 

1. What is the data type of print(type(5))?

A double

B float

C integer

D int

D
type() function gives the class type of the argument. The output is : <class 'int'>
 

2. Which of the following is not a built-in data type?

A Dictionary

B Lists

C Tuples

D Class

D
Class is not a built-in data type, but a user defined data type.
 

3. Which of the following statement is correct?

A List and Tuple are Immutable

B List and Tuple are Mutable

C Tuple is immutable and List is mutable

D Tuple is mutable and List is immutable

C
Tuple is immutable and List is mutable. A mutable data type means that an object of this type can be modified. An immutable object can not be modified.
 

4. What is the output of the following code?
str = "welcome"
print(str[:2])

A el

B we

C lc

D wel

B
We are displaying only the first two bytes of string, so the answer is “we”.
 

5. What is the return type of id() function?

A bool

B list

C int

D double

C
id() function returns an integer value that is unique. Example: Return the id of a tuple object:

color = ('blue', 'green', 'red')
x = id(color)

Output:

75342922
 

6. What is the data type of print(type(0xEE))?

A int

B hex

C hexint

D number

A
We can display integers in binary, octal and hexadecimal formats.

  • 0b or 0B for Binary
  • 0o or 0O for Octal
  • 0x or 0X for Hexadecimal
 

7. What is the output of the following code: print(type({}) is set)?

A True

B False

B
{} show an empty dictionary while set() is used to show an empty set.
 

8. In Python 3, what is the type of type(range(10))?

A tuple

B int

C range

D list

C
range() function gives a series of numbers, begining from 0, and increments by 1, and stops before a given number.
 

9. What type of error can arises when you execute the following code x = y?

A TypeError

B ValueError

C NameError

D SyntaxError

C
‘y’ is not defined so name error. The output:

Traceback (most recent call last):                                                                                                               
  File "main.py", line 11, in <module>                                                                                                           
    print(x = y)                                                                                                                                 
NameError: name 'y' is not defined
 

10. What is the output of the following code?
def test(n):
    n = n + '3'
     n = n * 3
    return n


print(test("hello"))

A hello3hello3hello3

B IndentationError

C hello3

D None of the mentioned

B
Output:

  File "main.py", line 11
    n = n * 3
    ^ 
IndentationError: unexpected indent
 

11. Suppose we have a list with 6 elements. You can get the second element from the list using ________

A mylist[-2]

B mylist[2]

C mylist[-1]

D mylist[1]

D
mylist[0] gives the first element while mylist[1] gives the second element.
 

12. What is the data type of the following object?
x = [5, 22, 'str', 1]

A tuple

B array

C dictionary

D list

D
List can store any values within it.
 

13. To store values as regards key and value we use ___________.

A tuple

B class

C dictionary

D list

C
To store values as regards key and value we use dictionary.
 

14. Can we use tuple as dictionary key?

A True

B False

A
A dictionary key have to be immutable. We can use a tuple as a key if the elements in the tuple are immutable.
 

15. What is the return value of trunc() function?

A bool

B int

C float

D None

B
trunc() function returns the truncated integer belong to a number. Example:

print(math.trunc(2.77)) #Output: 2
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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