Definition
Categories for values, where every value belongs to exactly one data type.
Why It Matters
Data types are the fundamental building blocks of all software. They ensure that operations are logically consistent and memory is used efficiently, preventing the “category errors” that lead to program crashes and data corruption.
Core Concepts
# Integers and Floats
count = 42 # int
price = 19.99 # float
# Strings
name = "Gemini" # str
# Operator Overloading
print(10 + 5) # 15 (Addition)
print("10" + "5") # "105" (Concatenation)
- Integers (
int): Whole numbers (e.g.,-2,42). - Floating-Point Numbers (
float): Numbers with decimal points (e.g.,3.14). Note that42is an integer, but42.0is a float. - Strings (
str): Text values enclosed in single'or double"quotes. - Operator Overloading: The meaning of an operator changes based on data types (e.g.,
+adds numbers but concatenates strings).