← Back to Python Course Foundations
Python Data Types
Learning Objectives
- Work with
str,int,float,complex,bool. - Convert between common types.
- Avoid conversion runtime errors.
Example
a = "42"
b = int(a)
c = float("3.5")
d = bool(1)
print(type(b), type(c), type(d))
Dry Run
int("42")->42float("3.5")->3.5bool(1)->True
Common Mistakes
- Converting non-numeric text directly to int/float.
- Assuming
"False"string becomesFalsewithbool().
Practice
- Read two numbers as input strings and add after conversion.
- Show successful and failed cast examples.