Skip to main 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.

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir