Python for Beginners and Intermediate Developers — A Complete Guide
Source: Dev.to
Why Python?
- Beginner‑friendly
- Easy to read and write
- Used in web development, data science, AI/ML, automation, DevOps, game development, and more
- Supported by a huge community
- Available on all major operating systems
1. Python Basics
1.1 Variables
name = "Farhad"
age = 20
is_active = True
print(name)
print(age)
print(is_active)
Explanation
- Strings use quotes.
- Integers do not use quotes.
- Boolean values start with a capital letter:
TrueorFalse.
1.2 Data Types
x = 10 # int
pi = 3.14 # float
name = "Python" # str
is_ok = True # bool
items = [1, 2, 3] # list
points = (4, 5) # tuple
user = {"name": "Ali", "age": 25} # dict
1.3 Input From User
username = input("Enter your name: ")
print("Hello, " + username)
1.4 Conditional Statements (if, elif, else)
age = 18
if age > 18:
print("You are an adult.")
elif age == 18:
print("You just turned 18!")
else:
print("You are under 18.")
2. Working With Loops
2.1 For Loop
for i in range(5):
print("Number:", i)
Explanation: range(5) generates numbers 0 to 4.
2.2 While Loop
count = 1
while count <= 5:
print(count)
count += 1
3. Functions
def greet(name):
print("Hello,", name)
greet("Farhad")
greet("Klie")
4. Lists, Tuples, and Dictionaries
4.1 Lists
fruits = ["apple", "banana", "orange"]
fruits.append("mango")
print(fruits)
4.2 Tuples (immutable)
point = (10, 20)
print(point[0])
4.3 Dictionaries
person = {
"name": "Farhad",
"age": 20
}
print(person["name"])
5. Intermediate Python Concepts
5.1 List Comprehension
numbers = [1, 2, 3, 4, 5]
squares = [x * x for x in numbers]
print(squares)
5.2 Lambda Functions
square = lambda x: x * x
print(square(5))
5.3 Map, Filter, Reduce
map()
nums = [1, 2, 3]
doubled = list(map(lambda x: x * 2, nums))
print(doubled)
filter()
nums = [1, 2, 3, 4, 5, 6]
even = list(filter(lambda x: x % 2 == 0, nums))
print(even)
5.4 Error Handling (try/except)
try:
number = int(input("Enter a number: "))
print("You entered:", number)
except ValueError:
print("Invalid number. Please enter digits only.")
5.5 Working With Files
Write to a file
with open("data.txt", "w") as f:
f.write("Hello, Python!")
Read from a file
with open("data.txt", "r") as f:
content = f.read()
print(content)
5.6 Object-Oriented Programming (OOP)
Class and Object Example
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
print(f"My name is {self.name}, and I am {self.age} years old.")
p1 = Person("Farhad", 20)
p1.introduce()
Explanation
__init__runs when an object is created.selfrefers to the current object.- Methods are functions defined inside classes.
6. Python Best Practices
- Use meaningful variable names.
- Keep functions small and reusable.
- Comment your code when needed.
- Follow PEP 8 style guidelines.
- Use virtual environments for project dependencies.
7. What You Can Build With Python
- Web applications (Django, Flask, FastAPI)
- Machine learning models (TensorFlow, PyTorch)
- Automation scripts
- API services
- Chatbots
- Data visualization tools
- Games (pygame)
Python is limitless once you learn the foundations.
Conclusion
Python is the perfect starting point for beginners and a powerful tool for intermediate developers. With its clean syntax and rich ecosystem, you can quickly build anything—from small scripts to large‑scale applications.