Python Basics - Quick Notes
Python Data Types
`int`: Whole numbers (e.g. `5`)
`float`: Decimal numbers (e.g. `3.14`)
`str`: Strings/text (e.g. "hello")
`bool`: Boolean values (`True`, `False`)
`list`, `tuple`, `dict`, `set`: Collection types
Python Numbers & Arithmetic
2+3 #5
5-2 #3
4*2 #8
10 / 2 # 5.0
5 ** 2 # 25
10 % 3 # 1 (remainder)
Variable Assignments
x = 10
name = "Alice"
pi = 3.14
Strings
my_string = "Hello, world!"
Indexing and Slicing:
my_string[0] # 'H'
my_string[-1] # '!'
my_string[0:5] # 'Hello'
String Methods:
my_string.upper() # 'HELLO, WORLD!'
my_string.lower() # 'hello, world!'
my_string.split(",") # ['Hello', ' world!']
Print Formatting:
name = "Alice"
age = 25
print(f"My name is {name} and I'm {age} years old.")
Lists
my_list = [1, 2, 3]
my_list.append(4)
print(my_list[0]) # 1
Dictionaries
my_dict = {"name": "Bob", "age": 30}
print(my_dict["name"]) # 'Bob'
Tuples
my_tuple = (1, 2, 3)
print(my_tuple[1]) # 2
Sets
my_set = {1, 2, 2, 3}
print(my_set) # {1, 2, 3}
Booleans
is_true = True
is_false = False
print(5 > 3) # True
print(3 == 4) # False