Module 04
Type Casting and Fundamental Conversions
Learn how to convert one data type into another safely and correctly.
01
What is Type Casting?
Learn why Python converts one possible type into another, and which five fundamental casting functions you will use.
02
int() — Convert to Integer
Learn which data types can be converted with int(), why some fail, and the difference between int(12.34) and int("12.34").
03
float() — Convert to Floating-Point
Convert integers, booleans, and numeric strings with float(), and see why complex values and non-numeric text fail.
04
bool() — Convert to Boolean
Convert values with bool() using the non-zero / zero rule for numbers and the non-empty / empty rule for strings.
05
complex() — Convert to Complex
Convert int, float, bool, and numeric strings with complex(). Use j, not i, and inspect .real and .imag.
06
str() — Convert to String
Convert int, float, bool, and complex values into text with str(), and see why converting back follows different rules.