Python Reviewer
Python Reviewer
# Python Reviewer
## Introduction to Python
- Python is a general-purpose, open-source programming language with a focus on readability.
- Features:
## Python Basics
### 1. Variables & Data Types
- Variables store values and do not need explicit declaration.
print(s[1:4]) # Slicing
print(s * 2) # Repetition
print(my_list[1]) # hello
## 2. Decision-Making Statements
### If Statement
if x > 10:
### If-Else
if x > 10:
else:
### If-Elif-Else
if x > 10:
print("Greater")
elif x == 10:
print("Equal")
else:
print("Smaller")
### Nested If
if x > 10:
if x % 2 == 0:
## 3. Loops in Python
### For Loop
for i in range(5): # 0 to 4
print(i)
while x < 5:
print(x)
x += 1
if i == 5:
for i in range(10):
if i == 5:
print(i)
## 4. Random Numbers
import random
x = random.randint(1, 10)
y = round(random.uniform(1.5, 10.5), 2)
## Summary
| Concept | Syntax Example |
|----------------------|---------------|
| Variable Assignment | x = 5 |