Skip to content

← 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") -> 42
  • float("3.5") -> 3.5
  • bool(1) -> True

Common Mistakes

  • Converting non-numeric text directly to int/float.
  • Assuming "False" string becomes False with bool().

Practice

  1. Read two numbers as input strings and add after conversion.
  2. Show successful and failed cast examples.