Python Data Types MCQ Questions and Answers

1. Which of the following is a complex number in Python?

a) 1 + 2j
b) 1.2
c) "1+2j"
d) [1, 2]

Answer:

a) 1 + 2j

Explanation:

In Python, a complex number is defined with a real part and an imaginary part, where the imaginary part is denoted by 'j'.

2. Which of these data types is immutable in Python?

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

Answer:

c) Tuple

Explanation:

Tuples in Python are immutable, meaning once a tuple is created, its elements cannot be altered.

3. What data type is the result of the expression 3 / 2 in Python 3?

a) int
b) float
c) str
d) complex

Answer:

b) float

Explanation:

In Python 3, the division of integers results in a float.

4. How do you represent a boolean false in Python?

a) False
b) false
c) 0
d) None

Answer:

a) False

Explanation:

Boolean values in Python are capitalized, so False is the correct representation.

5. What type of data does the following represent: ["apple", "banana", "cherry"]?

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

Answer:

c) List

Explanation:

This is a list, as it is enclosed in square brackets and contains an ordered collection of items.

6. What is the correct syntax for defining a dictionary in Python?

a) {key1: value1, key2: value2}
b) [key1: value1, key2: value2]
c) (key1: value1, key2: value2)
d) <key1: value1, key2: value2>

Answer:

a) {key1: value1, key2: value2}

Explanation:

Dictionaries in Python are defined with curly braces and consist of key-value pairs.

7. What will be the type of x after the assignment x = {"apple", "banana", "cherry"}?

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

Answer:

c) Set

Explanation:

The given syntax represents a set in Python, which is an unordered collection of unique items.

8. What is the output of type(10)?

a) <class 'int'>
b) <class 'float'>
c) <class 'str'>
d) <class 'num'>

Answer:

a) <class 'int'>

Explanation:

The number 10 is an integer, so its type is <class 'int'>.

9. Which data type would you use to store a sequence of characters in Python?

a) str
b) char
c) text
d) varchar

Answer:

a) str

Explanation:

In Python, strings are used to store sequences of characters and are defined with single or double quotes.

10. What is the output of this code: print(type({}))

a) <class 'list'>
b) <class 'set'>
c) <class 'dict'>
d) <class 'tuple'>

Answer:

c) <class 'dict'>

Explanation:

{} represents an empty dictionary in Python.

11. Which of the following is not a valid Python data type?

a) bytes
b) bytearray
c) frozenset
d) arraylist

Answer:

d) arraylist

Explanation:

'arraylist' is not a native data type in Python, whereas bytes, bytearray, and frozenset are.

12. What is the result of type(3.14)?

a) <class 'int'>
b) <class 'float'>
c) <class 'decimal'>
d) <class 'number'>

Answer:

b) <class 'float'>

Explanation:

3.14 is a floating-point number in Python.

13. Which method converts a string to an integer in Python?

a) int()
b) strToInt()
c) parse()
d) convert()

Answer:

a) int()

Explanation:

The int() function is used to convert a string into an integer in Python.

14. What will be the data type of x after x = b"Hello"?

a) str
b) bytes
c) bytearray
d) string

Answer:

b) bytes

Explanation:

The prefix b before the quotes indicates a bytes literal in Python.

15. How do you create an empty tuple in Python?

a) ()
b) []
c) {}
d) empty()

Answer:

a) ()

Explanation:

An empty tuple is created with an empty pair of parentheses ().


Comments