Numbers
# Integers (int):
age = 30
count = -5
# Floats (float):
price = 19.99
temperature = -3.5
# Complex (complex):
z = 3 + 4j
# Check type:
print(type(age)) #
print(type(price)) #
Strings
# Single or double quotes:
name1 = 'Alice'
name2 = "Bob"
# Multiline strings:
text = """This is
a multiline
string"""
# Check type:
print(type(name1)) #
Booleans
# True or False:
is_active = True
is_complete = False
# Result of comparisons:
result = 5 > 3 # True
print(type(result)) #
Type conversion
# Convert between types:
age_str = "30"
age_int = int(age_str) # 30
price_int = 19
price_float = float(price_int) # 19.0
number = 42
number_str = str(number) # "42"
# Check if conversion possible:
print(bool(1)) # True
print(bool(0)) # False
print(bool("")) # False
print(bool("hello")) # True
None
None represents "no value":
result = None
print(type(result)) #
# Common use:
def find_item(items, target):
for item in items:
if item == target:
return item
return None # Not found