Complete Python Learning Guide 🐍
1. Introduction to Python
Python is a beginner-friendly programming language known for its clear syntax and
powerful capabilities.
It is used in web development, AI, game development, data science, and more.
This guide is built to help you learn offline, step-by-step, through lessons, examples, and
challenges.
2. Printing and Inputs
The `print()` function is used to display information.
Example:
```python
print("Hello, World!")
```
The `input()` function gets input from the user.
```python
name = input("What is your name? ")
print("Nice to meet you,", name)
```
Challenge: Ask the user for their age and print a message.
3. Variables and Data Types
Variables store data.
```python
age = 20 # integer
name = "Joan" # string
height = 5.4 # float
is_student = True # boolean
```
You can combine them with print:
```python
print(name, "is", age, "years old.")
```
4. Conditions with if/else/elif
Conditions allow Python to make decisions.
```python
age = int(input("Enter age: "))
if age < 18:
print("You're a minor.")
elif age <= 30:
print("You're a young adult.")
else:
print("You're grown!")
```
Always end `if/elif` blocks with an `else` if you want a final option.
5. Loops (for, while)
Use `for` to loop through lists or ranges.
```python
for i in range(5):
print("This is loop number", i)
```
Use `while` to repeat something until a condition is met:
```python
attempts = 0
while attempts < 3:
password = input("Enter password: ")
if password == "secret":
print("Access granted")
break
attempts += 1
```
`break` stops the loop, `continue` skips to the next loop cycle.
6. Lists
Lists store multiple values.
```python
fruits = ["mango", "banana", "pineapple"]
print(fruits[0]) # mango
[Link]("apple") # add item
[Link]("banana") # remove item
```
Loop through a list:
```python
for fruit in fruits:
print("I love", fruit)
```
7. Functions
Functions group reusable code.
```python
def greet(name):
print("Hello,", name)
greet("Joan")
```
They can return values:
```python
def add(x, y):
return x + y
print(add(3, 5))
```
8. Dictionaries
Dictionaries store key-value pairs.
```python
user = {"name": "Joan", "age": 20, "role": "admin"}
print(user["name"]) # Joan
user["email"] = "a@[Link]" # add new value
```
Loop through a dictionary:
```python
for key, value in [Link]():
print(key, "=", value)
```
9. File I/O
Save or load data from files.
Save:
```python
with open("[Link]", "w") as file:
[Link]("This is my note.")
```
Read:
```python
with open("[Link]", "r") as file:
content = [Link]()
print(content)
```
10. Chatbot Project (AI Starter)
A simple rule-based chatbot:
```python
while True:
msg = input("You: ").lower()
if "hi" in msg:
print("Bot: Hello there!")
elif "bye" in msg:
print("Bot: Bye!")
break
else:
print("Bot: I don’t understand.")
```
Later, you can add AI libraries like `transformers` or `openai` for smarter bots.
Next Steps
Now that you’ve covered the essentials, here’s what to explore next:
- Object-Oriented Programming (OOP)
- Modules and libraries
- Building simple apps (to-do list, calculator)
- Game development with `pygame`
- AI with Python (machine learning, NLP)
Stay consistent. Practice daily. Keep building.