Python Data Types MCQ Questions

1. What is the data type of the following Python variable: x = 5?

a) String
b) Integer
c) Float
d) Character

Answer:

b) Integer

Explanation:

In Python, the variable 'x' assigned with a whole number (without a decimal point) is of integer type.

2. Which data type in Python is used to store a sequence of characters?

a) Char
b) String
c) Text
d) Word

Answer:

b) String

Explanation:

Python uses the string data type to store sequences of characters.

3. What data type would be used for a variable that holds the value 3.14 in Python?

a) Integer
b) Decimal
c) Double
d) Float

Answer:

d) Float

Explanation:

The float data type in Python represents floating-point numbers, which are numbers with a decimal point.

4. How is a list defined in Python?

a) Using curly braces {}
b) Using parentheses ()
c) Using square brackets []
d) Using angle brackets <>

Answer:

c) Using square brackets []

Explanation:

Lists in Python are defined using square brackets and can contain elements of different data types.

5. What type of data does a Python tuple store?

a) Only integers
b) Only strings
c) A sequence of immutable Python objects
d) Key-value pairs

Answer:

c) A sequence of immutable Python objects

Explanation:

A tuple in Python is a collection of Python objects that are immutable (cannot be changed after creation).

6. What is the data type of the following Python variable: x = True?

a) Integer
b) String
c) Boolean
d) Character

Answer:

c) Boolean

Explanation:

The variable 'x' in Python with the value True is of Boolean type, representing the logical values True or False.

7. What is a dictionary in Python?

a) A collection of words and their meanings
b) A list of numbers
c) A collection of key-value pairs
d) An immutable sequence of characters

Answer:

c) A collection of key-value pairs

Explanation:

In Python, a dictionary is a collection of key-value pairs where each key is unique and used to retrieve its corresponding value.

8. Which of the following is a mutable data type in Python?

a) Strings
b) Tuples
c) Lists
d) Integers

Answer:

c) Lists

Explanation:

Lists in Python are mutable, meaning their elements can be changed after their creation.

9. How do you define a set in Python?

a) With parentheses ()
b) With square brackets []
c) With curly braces {}
d) With angle brackets <>

Answer:

c) With curly braces {}

Explanation:

A set in Python is defined using curly braces and is an unordered collection of unique elements.

10. What is the output of the following Python code: type(8)?

a) <class 'int'>
b) <class 'number'>
c) <class 'integer'>
d) <class 'digit'>

Answer:

a) <class 'int'>

Explanation:

The type() function in Python shows that the value 8 is of integer class, denoted as <class 'int'>.

11. Which of the following data types does not allow duplicate values in Python?

a) Lists
b) Dictionaries
c) Tuples
d) Sets

Answer:

d) Sets

Explanation:

Sets in Python are collections of unique elements, meaning they do not allow duplicate values.

12. What is the correct syntax to create an empty list in Python?

a) list = ()
b) list = []
c) list = {}
d) list = set()

Answer:

b) list = []

Explanation:

An empty list in Python can be created using square brackets without any elements inside.

13. Which Python data type is used for ordered collections of items?

a) Sets
b) Tuples
c) Lists
d) Dictionaries

Answer:

c) Lists

Explanation:

Lists in Python are used for storing ordered collections of items and are one of the most versatile data types available.

14. What is the data type of the following Python variable: x = {"name": "John", "age": 30}?

a) List
b) Tuple
c) Set
d) Dictionary

Answer:

d) Dictionary

Explanation:

The variable 'x' is a dictionary in Python, as it is defined with curly braces containing key-value pairs.

15. In Python, what data type is best suited for storing a binary number like 0b1101?

a) Binary
b) String
c) Integer
d) Boolean

Answer:

c) Integer

Explanation:

Python stores binary numbers (e.g., 0b1101) as integers. The '0b' prefix indicates a binary literal.

16. What is the data type of the following Python variable: x = 3.14j?

a) Integer
b) Complex number
c) Float
d) Double

Answer:

b) Complex number

Explanation:

The 'j' suffix in Python denotes a complex number, making x a complex number with an imaginary part.

17. Which of the following Python data types is immutable?

a) Lists
b) Dictionaries
c) Tuples
d) Sets

Answer:

c) Tuples

Explanation:

Tuples in Python are immutable, meaning that their elements cannot be modified after they have been created.

18. What is the data type of the following Python variable: x = b"Hello"?

a) String
b) Byte
c) Binary
d) Bytearray

Answer:

b) Byte

Explanation:

The variable 'x' is a byte type in Python, indicated by the 'b' prefix before the string literal.

19. How do you define an integer variable 'a' in Python with the value 1000?

a) int a = 1000
b) a := 1000
c) a = 1000
d) integer a = 1000

Answer:

c) a = 1000

Explanation:

In Python, a variable is assigned a value using the '=' operator without specifying the data type.

20. What is the correct way to define a hexadecimal number in Python?

a) 0x1A
b) 1Ah
c) hex(1A)
d) #1A

Answer:

a) 0x1A

Explanation:

In Python, hexadecimal numbers are represented by prefixing the number with '0x' or '0X'.

Comments