Python Interview questions - data types
(Python version 3.9 or later version)
Python Interview Questions
Python - Data Types
1. What is the type of the following: 1
A) float
B) int
C) str
Answer: int
Explanation: As there is no decimal, the number is of type int
2. What is the type of the following "7.1"
A) float
B) int
C) str
Answer: str
Explanation: The type is string
3. What is the result of the following code segment: int(12.3)
A) 12.3
B) 12
C) 13
Answer: 12
Explanation: In Python, if you cast a float to an integer, the conversion truncates towards zero.
4. What is the result of the following code segment: int(True)
A) 1
B) 0
C) error
Answer: 1
Explanation: When you cast a boolean True to an integer you get a 1
5. What do you call a value that doesn’t have decimal values?
A) A number
B) An integer
C) A string
Answer: An integer
6. What do you call a value that does have decimal values?
A) A float
B) A number
C) An integer
Answer: A float
7. What data type can only have either a value of True or False?
A) A string
B) A boolean
C) An integer
Answer: A boolean
8. What code would turn the string “1” into an integer?
A)str(1)
B) int("1")
C) float("1")
Answer: int("1")
9. What character begins a single line comment?
A)'''
B) //
C) #
Answer:#
10. What do we call it when we convert from one data type to another?
A)casting
B) converting
C) changing
Answer:casting
11. What is the datatype of [Link]?
A) int
B) float
C) str
D) None
Answer: float
12. Which of the following numbers is NOT a float?
A) 1.5
B) 2.333333
C) 0.0
D) 0
Answer: 0
Explanation:0 on its own is an int. 0.0 however, is a float.
13. What values can the Boolean data type hold?
A) Integers, fractions, complex numbers
B) Unicode characters
C) True or False values
D) Any other data type
Answer: True or False values
14. WWhat does it mean that Python is a dynamically-typed language?
A) Variables in python can implicitly change to other types when comparing. For examples you can compare
B) Python variables can be assigned to different types and changes types at will.
C) Python is a more efficient language than C++
D) All of the above
Answer: Python variables can be assigned to different types and changes types at will.
Explanation: Dynamic-typing just refers to the ability for variables to flexibly learn their types during assign
Which of the following Python objects is immutable?
set
dict
list
str
What would be the result of executing the following code?
print(True*2)
TrueTrue
True True
2
Syntax Error
After executing the following line of code, what would be the data type of poll_data
poll_data = 7,
int
list
tuple
dict
Which of the following Python's built -in functions returns the type of the object that was pas
type( )
datatype( )
objtype( )
object( )
Which of the following statements, when executed, raises the TypeError?
dict(range(9))
set(range(9))
list(range(9))
tuple(range(9))
After executing the following line of code, what would be the data type of obj_data
obj_data = ( )
set
dict
tuple
list
Python Interview Questions
Python - Data Types
1. What is the type of the following: 1
A) float
B) int
C) str
Answer: int
Explanation: As there is no decimal, the number is of type int
2. What is the type of the following "7.1"
A) float
B) int
C) str
Answer: str
Explanation: The type is string
3. What is the result of the following code segment: int(12.3)
A) 12.3
B) 12
C) 13
Answer: 12
Explanation: In Python, if you cast a float to an integer, the conversion truncates towards zero.
4. What is the result of the following code segment: int(True)
A) 1
B) 0
C) error
Answer: 1
Explanation: When you cast a boolean True to an integer you get a 1
5. What do you call a value that doesn’t have decimal values?
A) A number
B) An integer
C) A string
Answer: An integer
6. What do you call a value that does have decimal values?
A) A float
B) A number
C) An integer
Answer: A float
7. What data type can only have either a value of True or False?
A) A string
B) A boolean
C) An integer
Answer: A boolean
8. What code would turn the string “1” into an integer?
A)str(1)
B) int("1")
C) float("1")
Answer: int("1")
9. What character begins a single line comment?
A)'''
B) //
C) #
Answer:#
10. What do we call it when we convert from one data type to another?
A)casting
B) converting
C) changing
Answer:casting
11. What is the datatype of [Link]?
A) int
B) float
C) str
D) None
Answer: float
12. Which of the following numbers is NOT a float?
A) 1.5
B) 2.333333
C) 0.0
D) 0
Answer: 0
Explanation:0 on its own is an int. 0.0 however, is a float.
13. What values can the Boolean data type hold?
A) Integers, fractions, complex numbers
B) Unicode characters
C) True or False values
D) Any other data type
Answer: True or False values
14. WWhat does it mean that Python is a dynamically-typed language?
A) Variables in python can implicitly change to other types when comparing. For examples you can compare
B) Python variables can be assigned to different types and changes types at will.
C) Python is a more efficient language than C++
D) All of the above
Answer: Python variables can be assigned to different types and changes types at will.