Diving into the world of Python programming is an exciting journey, and understanding the basic data types is a important step. Python offers a diverse range of built-in data types, from simple integers and floats to complex lists and dictionaries.
In this page, we’ve prepared a set of 15 Multiple Choice Questions (MCQs) specifically designed for beginners to evaluate their understanding of Python’s data types. Accompanying each question is a detailed explanation to enhance your learning experience. Let’s get started!
1. What is the data type of: 5?
Answer:
Explanation:
The value 5 without a decimal point is an integer.
2. Which of the following is a mutable data type?
Answer:
Explanation:
Lists in Python can be altered after their creation, hence they are mutable. Other options are immutable.
3. Which data type is ordered and changeable, and allows duplicate members?
Answer:
Explanation:
A list is ordered, can be altered, and can have duplicate members.
4. What does the following code produce: type(5.0)?
Answer:
Explanation:
5.0 is a floating-point number, so the type function will return float.
5. Which of the following can’t be a dictionary key?
Answer:
Explanation:
Dictionary keys must be immutable, and since lists are mutable, they can’t be used as dictionary keys.
6. Which data type is unordered and unindexed?
Answer:
Explanation:
Sets in Python are both unordered and unindexed.
7. Which of these is used to represent a sequences of characters?
Answer:
Explanation:
Strings are sequences of characters in Python.
8. Which data type cannot contain duplicate values?
Answer:
Explanation:
Sets are unindexed collections of unique elements. They don’t allow duplicates.
9. What is the output of type((1,2))?
Answer:
Explanation:
The values 1 and 2 enclosed in parentheses form a tuple.
10. Which of the following data types does not allow slicing?
Answer:
Explanation:
Sets are unordered and unindexed, so slicing operations are not supported.
11. Which data type is immutable?
Answer:
Explanation:
Strings in Python are immutable, meaning their values can’t be altered after they’re created.
12. How can you represent complex numbers in Python?
Answer:
Explanation:
In Python, complex numbers are represented as a+bj, where a and b are floats.
13. Which of the following is not a Python data type?
Answer:
Explanation:
While classes are used to define new types in Python, they themselves aren’t a data type.
14. Which data type is mutable but ordered?
Answer:
Explanation:
Lists are ordered collections of elements and they can be modified after their creation.
15. Which data type can be used to represent a pair of values?
Answer:
Explanation:
Tuples can hold an ordered collection of items, which can be of any type