Python Basics Notes
Python Basics Notes
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!"
my_string[0] # 'H'
my_string[-1] # '!'
my_string[0:5] # 'Hello'
String Methods:
Print Formatting:
name = "Alice"
age = 25
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(3 == 4) # False