Understanding Numeric Types
Numbers are everywhere in Python. You'll use two core numeric types most of the time: integers (int) for whole numbers and floating-point numbers (float) for decimals (including scientific notation like 1e-3).
Integer and Float Essentials
- Integers (
int): whole numbers such as-2,0,7,456566. Python supports arbitrarily large integers; - Floats (
float): decimal values such as2.5,3.14159,2.71828, or scientific notation like6.02e23; - Truthiness:
0and0.0areFalse, any otherint/floatisTruein boolean contexts.
Scientific Notation
Scientific notation is a compact way to write very large or very small numbers using powers of ten. In Python, a number written with e means βmultiply by 10 raised to a powerβ: for example, 1e-3 means 1Γ10β3 (0.001), and 6.02e23 means 6.02Γ1023. Numbers written in this form are always treated as float.
123456# Basic numeric literals n_int = 42 n_float = 3.14 n_sci = 1e-3 # 0.001 print(n_int, n_float, n_sci)
Writing Large Numbers Readably
Humans often write 1,000,000 or 1 000 000. Python doesn't allow commas or spaces inside numeric literals, use underscores for readability.
12million = 1_000_000 print(million == 1000000) # True
Floats are stored as binary fractions, tiny rounding differences are normal (e.g., 0.1 + 0.2 may not be exactly 0.3). You'll handle rounding and formatting later.
1. What is the type of 1e2?
2. Which literal is valid in Python code for one million?
3. Pick the true statement about int and float.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.45
Understanding Numeric Types
Swipe to show menu
Numbers are everywhere in Python. You'll use two core numeric types most of the time: integers (int) for whole numbers and floating-point numbers (float) for decimals (including scientific notation like 1e-3).
Integer and Float Essentials
- Integers (
int): whole numbers such as-2,0,7,456566. Python supports arbitrarily large integers; - Floats (
float): decimal values such as2.5,3.14159,2.71828, or scientific notation like6.02e23; - Truthiness:
0and0.0areFalse, any otherint/floatisTruein boolean contexts.
Scientific Notation
Scientific notation is a compact way to write very large or very small numbers using powers of ten. In Python, a number written with e means βmultiply by 10 raised to a powerβ: for example, 1e-3 means 1Γ10β3 (0.001), and 6.02e23 means 6.02Γ1023. Numbers written in this form are always treated as float.
123456# Basic numeric literals n_int = 42 n_float = 3.14 n_sci = 1e-3 # 0.001 print(n_int, n_float, n_sci)
Writing Large Numbers Readably
Humans often write 1,000,000 or 1 000 000. Python doesn't allow commas or spaces inside numeric literals, use underscores for readability.
12million = 1_000_000 print(million == 1000000) # True
Floats are stored as binary fractions, tiny rounding differences are normal (e.g., 0.1 + 0.2 may not be exactly 0.3). You'll handle rounding and formatting later.
1. What is the type of 1e2?
2. Which literal is valid in Python code for one million?
3. Pick the true statement about int and float.
Thanks for your feedback!