Python — Data Types
What is a data type?
A data type tells Python what kind of value a variable contains.
Common built-in types
int — whole numbers: 10, -5, 0
float — decimal numbers: 10.5, 3.14
str — text: "Hello"
bool — logical values: True, False
list — ordered, changeable collection: [1, 2, 3]
tuple — ordered, unchangeable collection: (1, 2, 3)
set — unordered collection of unique values: {1, 2, 3}
dict — key-value pairs: {'name': 'Aryan'}
Checking a type
x = 10
print(type(x))
Output: <class 'int'>
Type conversion
int("10") # 10
float("10.5") # 10.5
str(100) # "100"
bool(1) # True
Important idea
Some values are truthy and some are falsy. For example, an empty string "" is falsy, while a non-empty string is truthy.
Quick memory
int = whole number | float = decimal | str = text | bool = True/False