PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Easy
Question 22
Q637 - Data Types
Consider the following Python code:
- distance = 1876.23
- amount = +42E7
- country = 'Italy'
What are the types of the variables distance, amount and country?
-
A
float, int, str
-
B
float, float, str
-
C
float, str, str
-
D
double, str, float
Reveal correct answer
Correct answer: B
Explanation
Topics: integer float string scientific notation
Try it yourself:
- print(type(1876.23)) # <class 'float'>
- print(type(+42E7)) # <class 'float'>
- print(type('Italy')) # <class 'str'>
- print(10e6) # 10000000.0
Explanation:
There is no double in Python.
The scientific notation always returns a float
The letter E is called exponent and it does not matter whether you use e or E
Q637 (Please refer to this number, if you want to write me about this question.)
A. The variable 'distance' is assigned a floating-point number, so its type is float. The variable 'amount' is assigned a number with scientific notation, which is still a floating-point number, not an integer, so its type is float. The variable 'country' is assigned a string, so its type is str.
B. The variable 'distance' is assigned a floating-point number, so its type is float. The variable 'amount' is assigned a number in scientific notation, which is also a floating-point number, so its type is float. The variable 'country' is assigned a string, so its type is str.
C. The variable 'distance' is assigned a floating-point number, so its type is float. The variable 'amount' is assigned a number in scientific notation, which is a floating-point number, not a string, so its type is float. The variable 'country' is assigned a string, so its type is str.
D. There is no 'double' data type in Python. The variable 'distance' is assigned a floating-point number, so its type is float. The variable 'amount' is assigned a number in scientific notation, which is a floating-point number, not a string, so its type is float. The variable 'country' is assigned a string, so its type is str.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
