Python Notes 5 Pages
Python Notes 5 Pages
Basic Syntax:
Data Types:
Conditional Statements:
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
Loops:
- while loop:
i=0
while i < 5:
print(i)
i += 1
- for loop:
for i in range(5):
print(i)
Page 3: Functions and Modules
Functions:
def greet(name):
Modules:
Lists:
- Ordered, mutable
- my_list = [1, 2, 3]
Tuples:
- Ordered, immutable
- my_tuple = (1, 2, 3)
Dictionaries:
- Key-value pairs
Sets:
- my_set = {1, 2, 3}
Page 5: Object-Oriented Programming
class Person:
self.name = name
self.age = age
def greet(self):
p = Person("Alice", 30)
print(p.greet())
Concepts: