Python Data Types Quiz
- Last Updated On
- ByScientech Easy
- InPython
- Read Time4 mins
1. What is a data type in Python?
A way to define a variable.
A specific type of value that a variable can store.
A method to allocate memory for a program.
None of these
b
A data type in Python defines a specific type of value that a variable can store, such as an integer, string, boolean, etc.
2. What is the data type of the value 50 in the following code?
num = 50
float
str
int
bool
c
In the above code, the value 50 is an integer, so its data type is int.
3. Which of the following is a mutable data type in Python programming?
Tuple
String
List
Integer
c
A list is a mutable data type, meaning that its elements can be modified, added, or removed after creation, whereas tuples, strings, and integers are immutable.
4. Which of the following is not a fundamental or native data type in Python?
int
float
complex
string
d
Fundamental data types in Python are int, float, and complex. String is a sequence data type in Python.
5. Which of the following is a sequence data type in Python?
int
float
string
dictionary
c
String, list, and tuple are sequence data types in Python. int and float are fundamental data types, and dictionary is a mapping data type.
6. Which of the following is not a core data type in Python?
Lists
Dictionary
Tuples
Class
d
Class is a user-defined data type.
7. What is the data type of the object below?
list = [1, 23, 'Scientech Easy', 10]
int
str
list
tuple
c
The object is a list because it is enclosed in square brackets [ ] and contains heterogeneous elements.
8. Which of the following data type in Python maintains the order of elements inserted?
set
list
dic
Both b and c
d
Lists always maintain the order of elements as they were inserted. Dictionaries (dict) in Python 3.7 and onwards also maintain the insertion order of keys by default.
9. What is the output of the following code?
x = 5 print(type(x))
<class ‘int’>
<class ‘float’>
<class ‘str’>
<class ‘list’>
a
The type() function returns the data type of the variable.
10. Which of the following statements correctly defines a tuple?
t = (10, 20, 30)
t = [10, 20, 30]
t = {10, 20, 30}
None of these
a
A tuple can be defined using parentheses ( ), but it can also be created without parentheses using a comma-separated sequence (t = 10, 20, 30).
11. What will be the output of the following code?
nums = {1, 2, 3, 3, 2, 1} print(nums)
{1, 2, 3}
{1, 1, 2, 2, 3, 3}
[1, 2, 3]
(1, 2, 3)
a
A set in Python stores only unique values, so duplicates are removed automatically.
12. What happens if you attempt to store a string value in a variable that was previously assigned an integer in Python?
Python forces explicit type declaration before changing the type.
The variable remains an integer, and the string is ignored.
Python will allow it because variables are dynamically typed.
Python throws a TypeError immediately.
c
In Python, variables are dynamically typed, meaning that you don’t need to explicitly declare the type of variable when you create it. The type of variable is determined at runtime based on the value assigned to it. You can reassign a variable to a value of a different type without any issues. For example, if a variable initially holds an integer value and is later assigned a string value, Python simply updates the type of the variable without throwing an error. However, performing arithmetic operations on a string without conversion will cause a TypeError.
13. Which of the following statements is true about data types in Python?
All data types occupy the same amount of memory.
Data types are exclusively used for numerical values.
Data types determine the operations that are performed on the data.
Data types are not necessary in Python
c
Data types define what kind of operations you can perform on the data. For example, you can add two integers (5 + 3 = 8), but you cannot add an integer and a string directly.
14. Which of the following statements about data types in Python is incorrect?
Python supports different data types for numbers, strings, lists, dictionaries.
Different data types occupy different memory sizes depending on their type and values.
None is not a data type in Python
Boolean data type is defined as a bool class in Python.
c
None is a special data type in Python, represented by the NoneType class.
15. What error will occur if you try to add an integer to a string in Python?
x = "Scientech Easy" y = x + 5
SyntaxError
ValueError
NameError
TypeError
d
Python does not allow to add a string (“Scientech Easy”) and an integer (5) without explicit conversion. If you try, it will give a TypeError, indicating an unsupported operand type. To fix this, you convert the integer to a string like this (x + str(5)).