Python's core built-in types:
name = "Alice" # str
age = 30 # int
height = 1.75 # float
active = True # bool
nothing = None # NoneType
# Check type at runtime
print(type(age)) # <class 'int'>
print(isinstance(name, str)) # True
Strings are immutable sequences of Unicode characters. Common operations:
s = "Hello, World!"
print(s.upper()) # HELLO, WORLD!
print(s.lower()) # hello, world!
print(s.replace("World", "Python")) # Hello, Python!
print(s.split(", ")) # ['Hello', 'World!']
print(len(s)) # 13
print(s[0:5]) # Hello (slice)
print(f"Name: {name}, Age: {age}") # f-string formatting
Python numbers are arbitrary precision, so integers never overflow. Division always returns a float; use // for integer division:
print(10 / 3) # 3.3333333333333335
print(10 // 3) # 3
print(10 % 3) # 1 (modulo / remainder)
print(2 ** 10) # 1024 (exponentiation)