Python Me
Python Me
- What is Python?
Example
print("Hello, World!")
Example
age = 30
name = "John"
is_student = True
height = 5.9
Chapter 3: Operators
a = 10
b=3
# Arithmetic operations
sum_result = a + b # 13
division_result = a / b # 3.33
# Comparison
is_equal = (a == b) # False
# Logical operations
Example
# If-Else Example
age = 18
print("Adult")
else:
print("Minor")
# For loop
for i in range(5):
print(i)
# While loop
count = 0
while count < 3:
print("Count:", count)
count += 1
Chapter 5: Functions
Example
def greet(name="User"):
- Creating lists.
- List slicing.
Example
# List slicing
Example
# Access value
Chapter 8: Tuples
- Tuple operations.
- Unpacking tuples.
Example
x, y = coordinates
print(x, y) # Output: 10 20
- Formatting strings.
- Basic output with print().
Example
print(f"Hello, {name}")
Example
content = file.read()
print(content)
# Writing to a file
file.write("Hello, World!")
Example
try:
result = 10 / num
except ZeroDivisionError:
finally:
print("Execution completed.")
- Basic inheritance.
Example
class Car:
self.model = model
self.year = year
def display_info(self):
# Creating an object
- Moving on to intermediate topics like modules, decorators, and working with libraries.