DEV Community

Cover image for Python for Beginners and Intermediate Developers — A Complete Guide
Farhad Rahimi Klie
Farhad Rahimi Klie

Posted on

Python for Beginners and Intermediate Developers — A Complete Guide

Python is one of the most widely used programming languages in the world. Its clean syntax, massive ecosystem of packages, and versatility make it perfect for beginners and powerful enough for intermediate and advanced developers.

In this article, you will learn Python step-by-step—from fundamentals to intermediate-level concepts—with fully explained examples you can copy, paste, and run.


Why Python?

Python is popular because it is:

  • 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

Let’s begin with the essentials.


1. Python Basics

1.1 Variables

A variable stores data.

name = "Farhad"
age = 20
is_active = True

print(name)
print(age)
print(is_active)
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • Strings use quotes.
  • Integers do not use quotes.
  • Boolean values start with a capital letter: True or False.

1.2 Data Types

Python has several built-in 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
Enter fullscreen mode Exit fullscreen mode

1.3 Input From User

username = input("Enter your name: ")
print("Hello, " + username)
Enter fullscreen mode Exit fullscreen mode

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.")
Enter fullscreen mode Exit fullscreen mode

2. Working With Loops

2.1 For Loop

for i in range(5):
    print("Number:", i)
Enter fullscreen mode Exit fullscreen mode

Explanation:
range(5) generates numbers 0 to 4.


2.2 While Loop

count = 1

while count <= 5:
    print(count)
    count += 1
Enter fullscreen mode Exit fullscreen mode

3. Functions

Functions help you avoid repeating code.

def greet(name):
    print("Hello,", name)

greet("Farhad")
greet("Klie")
Enter fullscreen mode Exit fullscreen mode

4. Lists, Tuples, and Dictionaries

4.1 Lists

fruits = ["apple", "banana", "orange"]
fruits.append("mango")

print(fruits)
Enter fullscreen mode Exit fullscreen mode

4.2 Tuples (immutable)

point = (10, 20)
print(point[0])
Enter fullscreen mode Exit fullscreen mode

4.3 Dictionaries

person = {
    "name": "Farhad",
    "age": 20
}

print(person["name"])
Enter fullscreen mode Exit fullscreen mode

5. Intermediate Python Concepts

Let’s move to the next level.


5.1 List Comprehension

A faster, cleaner way to create lists.

numbers = [1, 2, 3, 4, 5]
squares = [x * x for x in numbers]

print(squares)
Enter fullscreen mode Exit fullscreen mode

5.2 Lambda Functions

Small, anonymous functions.

square = lambda x: x * x
print(square(5))
Enter fullscreen mode Exit fullscreen mode

5.3 Map, Filter, Reduce

map()

nums = [1, 2, 3]
doubled = list(map(lambda x: x * 2, nums))
print(doubled)
Enter fullscreen mode Exit fullscreen mode

filter()

nums = [1, 2, 3, 4, 5, 6]
even = list(filter(lambda x: x % 2 == 0, nums))
print(even)
Enter fullscreen mode Exit fullscreen mode

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.")
Enter fullscreen mode Exit fullscreen mode

5.5 Working With Files

Write to a file

with open("data.txt", "w") as f:
    f.write("Hello, Python!")
Enter fullscreen mode Exit fullscreen mode

Read from a file

with open("data.txt", "r") as f:
    content = f.read()
    print(content)
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • __init__ runs when an object is created.
  • self refers to the current object.
  • Methods are functions 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

After mastering basics and intermediate concepts, you can build:

  • 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.

Top comments (0)