Free Online Course · Self-paced · Hands-on

Python Tutorial for Beginners (Hands-On)

Free Python tutorial for beginners: 160+ hands-on lessons on data types, loops, OOP, file I/O, regex, concurrency, and Flask, tested on Python 3.13.

  • 19 chapters
  • 167 lessons
  • ~16h
  • Beginner to Intermediate
  • Tested with Python 3.13.x
  • Updated Sep 2026
Python Tutorial for Beginners (Hands-On)
By Last updated

About this course

This is a free, self-paced Python course that goes from variables and print() to a Flask web app running behind Gunicorn and Nginx. It covers the built-in data types, control flow, functions, classes, files, regular expressions, subprocesses, and concurrency, mostly with the standard library that ships with every Python release. Python 3.14 is the current stable version, and most lessons were run on Python 3.13.

Each lesson is written around small programs you can paste into the interpreter or save as a script, followed by the output they printed when we ran them. When a lesson needs a third-party package, it names the version it was run against, so a result that differs from yours usually points at a version mismatch rather than a typo.

If Python is your first language, work through the chapters in order. If you already know the basics, jump to lists, tuples, and sets, object-oriented Python, or the Flask chapter.

What you'll learn

  • Write and print variables, numbers, and strings, and format output with f-strings
  • Control program flow with if, match/case, for, while, range(), and enumerate()
  • Choose between lists, tuples, sets, and dictionaries, and sort, merge, and nest them
  • Write functions with default arguments, *args, **kwargs, generators, and comprehensions
  • Build classes with constructors, inheritance, @classmethod, @staticmethod, dataclasses, and enums
  • Handle exceptions, write custom exception classes, and log with the logging module
  • Read and write files, CSV, YAML, and ZIP archives, run subprocesses, and parse CLI arguments with argparse
  • Use threads and processes for concurrent work, then build and deploy a Flask web app

Who this course is for

  • Complete beginners who want a first language that reads close to plain English
  • Sysadmins and DevOps engineers replacing long shell scripts with Python they can test and reuse
  • Developers from Java, C, or JavaScript who want idiomatic Python rather than their old habits in new syntax
  • Students and job seekers preparing for Python coding interviews

Prerequisites

  • Python 3.12 or newer on Linux, macOS, or Windows; the lesson output comes from Python 3.13
  • On Ubuntu, install latest Python on Ubuntu beside system python3; on Debian, install latest Python on Debian instead of replacing the python3 that apt depends on
  • Comfortable at the command line, and a code editor such as VS Code or PyCharm
  • No prior programming experience, and no paid accounts or cloud services

Versions and testing environment

Every command in this course was run on this stack

ComponentVersionNotes
Python 3.13.x Most lessons were run with Python 3.13.3 on Ubuntu 25.04 (kernel 6.14)
Python 3.12.x, 3.14.x A few lessons were run on Python 3.12.13 on RHEL 10.2 and Python 3.14.6 on Kali Linux
Data libraries NumPy 2.2.3, pandas 3.0.3, Matplotlib 3.8.3, seaborn 0.13.2 Needed only for the NumPy and Matplotlib chapter; install them with pip in a virtual environment
Tooling pip 25.0, Pylint 4.0.6, requests 2.32.3 Versions used in the packaging, linting, and HTTP lessons

Syllabus

19 chapters · 167 lessons · ~16h of reading

  1. 1 Getting Started 9 lessons · ~1h 20m
    1. Part 1 Beginner tips for learning Python 7 min read
    2. Part 2 Python functions explained 8 min read
    3. Part 3 Call functions in Python 9 min read
    4. Part 4 Lambda (anonymous) functions 7 min read
    5. Part 5 Create and publish a Python package 18 min read
    6. Part 6 requirements.txt - manage dependencies 9 min read
    7. Part 7 Install a package directly from GitHub 8 min read
    8. Part 8 Multiline comments 6 min read
    9. Part 9 Line continuation 8 min read
  2. 2 Variables, Numbers, Strings 24 lessons · ~2h 32m
    1. Part 10 Check the type of a variable 9 min read
    2. Part 11 Print variables (f-strings and beyond) 6 min read
    3. Part 12 Python numbers - int, float, complex 7 min read
    4. Part 13 String formatting (f-strings, format(), %) 6 min read
    5. Part 14 Concatenate strings 6 min read
    6. Part 15 Extract a substring 6 min read
    7. Part 16 Split a string 6 min read
    8. Part 17 Check if a string contains a substring 7 min read
    9. Part 18 str.startswith() method 5 min read
    10. Part 19 str.strip() and friends 6 min read
    11. Part 20 Reverse a string 5 min read
    12. Part 21 Compare strings 8 min read
    13. Part 22 Multi-line strings 8 min read
    14. Part 23 Global variables 7 min read
    15. Part 24 Delete a variable 7 min read
    16. Part 25 None and null checks 8 min read
    17. Part 26 str.casefold() for case-insensitive text 5 min read
    18. Part 27 Check if a string is an integer 6 min read
    19. Part 28 Mask user input (asterisks) 6 min read
    20. Part 29 Copy a string safely 7 min read
    21. Part 30 str.isupper() and case checks 5 min read
    22. Part 31 Unique characters in a string 4 min read
    23. Part 32 Append to strings efficiently 7 min read
    24. Part 33 Replace text in a file 5 min read
  3. 3 Operators, Conditions, Pattern Matching 6 lessons · ~1h 1m
    1. Part 34 Python operators (arithmetic, comparison, logical, bitwise) 7 min read
    2. Part 35 if / elif / else 12 min read
    3. Part 36 One-line if/else 8 min read
    4. Part 37 Ternary operator 7 min read
    5. Part 38 switch/case equivalents in Python 8 min read
    6. Part 39 match / case (structural pattern matching) 19 min read
  4. 4 Loops and Iteration 13 lessons · ~1h 26m
    1. Part 40 for loop 6 min read
    2. Part 41 One-line for loops (comprehensions) 6 min read
    3. Part 42 while loop 8 min read
    4. Part 43 while with multiple conditions 6 min read
    5. Part 44 Loop N times 5 min read
    6. Part 45 Loop through lists 8 min read
    7. Part 46 break statement 9 min read
    8. Part 47 continue statement 7 min read
    9. Part 48 pass statement 8 min read
    10. Part 49 pass vs break vs continue 4 min read
    11. Part 50 range() function 7 min read
    12. Part 51 enumerate() 7 min read
    13. Part 52 Reverse range() patterns 5 min read
  5. 5 Lists, Tuples and Sets 19 lessons · ~2h 21m
    1. Part 53 Python lists explained 9 min read
    2. Part 54 list vs set vs tuple vs dictionary 9 min read
    3. Part 55 list.pop() 9 min read
    4. Part 56 list.extend() 7 min read
    5. Part 57 append() vs extend() 6 min read
    6. Part 58 Remove elements from a list 7 min read
    7. Part 59 Concatenate lists 8 min read
    8. Part 60 Flatten a nested list 5 min read
    9. Part 61 Sort a list 7 min read
    10. Part 62 Copy a list (shallow vs deep) 8 min read
    11. Part 63 Python tuples 9 min read
    12. Part 64 Python sets 7 min read
    13. Part 65 Add to a set 7 min read
    14. Part 66 Set intersection 15 min read
    15. Part 67 Set difference 9 min read
    16. Part 68 Set symmetric difference 6 min read
    17. Part 69 Length of a set 4 min read
    18. Part 70 Print a list in reverse with range() 4 min read
    19. Part 71 Join lists together 5 min read
  6. 6 Dictionaries 10 lessons · ~1h 15m
    1. Part 72 Python dictionaries explained 8 min read
    2. Part 73 Add to a dictionary 6 min read
    3. Part 74 Extend a dictionary 7 min read
    4. Part 75 Nested dictionaries 12 min read
    5. Part 76 Sort a dict by key 8 min read
    6. Part 77 Sort a dict by value 7 min read
    7. Part 78 Remove a key from a dict 7 min read
    8. Part 79 Merge two dicts 8 min read
    9. Part 80 Nested dictionary patterns 8 min read
    10. Part 81 Slice or partition dictionary data 4 min read
  7. 7 Functions and Arguments 6 lessons · ~39 min
    1. Part 82 Call a function from another file 6 min read
    2. Part 83 Return multiple values from a function 7 min read
    3. Part 84 Optional arguments and defaults 7 min read
    4. Part 85 *args and **kwargs 5 min read
    5. Part 86 yield and generators 7 min read
    6. Part 87 next() and iterators 7 min read
  8. 8 Functional Tools and Comprehensions 7 lessons · ~52 min
    1. Part 88 List comprehensions 11 min read
    2. Part 89 map() function 6 min read
    3. Part 90 filter() function 7 min read
    4. Part 91 zip() function 9 min read
    5. Part 92 any() — test if any item is true 7 min read
    6. Part 93 all() — test if every item is true 5 min read
    7. Part 94 len() — length of sequences and collections 7 min read
  9. 9 Object-Oriented Python 8 lessons · ~1h 7m
    1. Part 95 Define a class 7 min read
    2. Part 96 Constructors (__init__) 11 min read
    3. Part 97 @classmethod 9 min read
    4. Part 98 @staticmethod 7 min read
    5. Part 99 super() and inheritance 7 min read
    6. Part 100 @dataclass 11 min read
    7. Part 101 Enum types 9 min read
    8. Part 102 The @deleter property decorator 6 min read
  10. 10 Error Handling and Logging 6 lessons · ~50 min
    1. Part 103 try / except basics 9 min read
    2. Part 104 Catch multiple exceptions 6 min read
    3. Part 105 Custom exceptions 8 min read
    4. Part 106 Exit a script cleanly 7 min read
    5. Part 107 The logging module 9 min read
    6. Part 108 FileNotFoundError handling 11 min read
  11. 11 File I/O 13 lessons · ~1h 14m
    1. Part 109 Check if a file exists 7 min read
    2. Part 110 Write to a file 6 min read
    3. Part 111 writelines() method 5 min read
    4. Part 112 Delete a file 7 min read
    5. Part 113 Read and write CSV 7 min read
    6. Part 114 Read YAML into a dict 6 min read
    7. Part 115 os.path.join() 7 min read
    8. Part 116 Create nested directories 6 min read
    9. Part 117 Get a file's extension 5 min read
    10. Part 118 Get a file's size 6 min read
    11. Part 119 Work with zip archives Coming soon
    12. Part 120 Persistent dict-like storage (shelve) 6 min read
    13. Part 121 Unix password database (pwd) 6 min read
  12. 12 Regex, Dates and Utilities 8 lessons · ~49 min
    1. Part 122 Python regex (re module) 8 min read
    2. Part 123 datetime basics 9 min read
    3. Part 124 Convert datetime to timestamp 5 min read
    4. Part 125 Generate UUIDs 7 min read
    5. Part 126 Measure execution time 6 min read
    6. Part 127 Generate sample GPS coordinates 6 min read
    7. Part 128 Get the user home directory 5 min read
    8. Part 129 Date math (months ago) 3 min read
  13. 13 Subprocess, CLI and HTTP 6 lessons · ~55 min
    1. Part 130 argparse - parse CLI arguments 9 min read
    2. Part 131 Read user input 6 min read
    3. Part 132 Run shell commands (subprocess) 15 min read
    4. Part 133 HTTP requests with the requests library 8 min read
    5. Part 134 Progress bars in the terminal 8 min read
    6. Part 135 Binary data packing (struct) 9 min read
  14. 14 Math, rounding, and sorting 5 lessons · ~33 min
    1. Part 136 math.ceil() and ceiling values 6 min read
    2. Part 137 math.floor() and flooring values 6 min read
    3. Part 138 round() and rounding patterns 8 min read
    4. Part 139 pow() and exponentiation 7 min read
    5. Part 140 sorted() and list.sort() overview 6 min read
  15. 15 Linting, testing, and packaging extras 5 lessons · ~32 min
    1. Part 141 Lint code with Pylint 9 min read
    2. Part 142 pytest and logging together 5 min read
    3. Part 143 collections.Counter 9 min read
    4. Part 144 Marshmallow serialization and validation 9 min read
    5. Part 145 Cobalt Strike automation library (overview) Coming soon
  16. 16 Data structures and algorithms 3 lessons · ~32 min
    1. Part 146 Tree data structures in Python 14 min read
    2. Part 147 Binary search tree 12 min read
    3. Part 148 Priority queue size patterns 6 min read
  17. 17 NumPy, Matplotlib, PyTorch, and related snippets 13 lessons · ~1h 17m
    1. Part 149 Matplotlib basics 9 min read
    2. Part 150 pyplot.figure() patterns 9 min read
    3. Part 151 plt.vlines() for vertical lines 3 min read
    4. Part 152 Seaborn scatter plots 6 min read
    5. Part 153 NumPy random number examples 10 min read
    6. Part 154 NumPy assignment and broadcasting pitfalls 5 min read
    7. Part 155 Shuffle two NumPy arrays in sync 5 min read
    8. Part 156 Combine two-column matrices 6 min read
    9. Part 157 Sort names in reverse alphabetic order 5 min read
    10. Part 158 Lowercase an entire DataFrame 3 min read
    11. Part 159 Concatenate tensors in PyTorch 8 min read
    12. Part 160 Circular color gradients in Python Coming soon
    13. Part 161 Facebook AI Similarity Search (Faiss) API 8 min read
  18. 18 Concurrency 2 lessons · ~18 min
    1. Part 162 Multithreading in Python 8 min read
    2. Part 163 Multiprocessing in Python 10 min read
  19. 19 Web with Flask 4 lessons · ~1h 5m
    1. Part 164 Build a Flask web app 21 min read
    2. Part 165 Flask Jinja2 templates 12 min read
    3. Part 166 Flask + SQLAlchemy 20 min read
    4. Part 167 Deploy Flask with Gunicorn + Nginx 12 min read

Hands-on labs

6 guided builds you run yourself

  1. Build a command-line tool with argparse

    Add positional arguments, typed options, choices, boolean flags, and subcommands to a script.

  2. Implement a binary search tree

    Write insert, search, delete, and the three traversals on a Node class, including the two-child delete case.

  3. Package and publish your own module

    Lay out a package, configure it, build it, test it locally, and publish it.

  4. Build a blog with Flask and SQLite

    Create, edit, and delete blog posts through Jinja2 templates backed by an SQLite database.

  5. Model data with Flask-SQLAlchemy

    Replace hand-written SQL with db.Model classes and query them from Flask routes.

  6. Deploy Flask behind Gunicorn and Nginx

    Serve the app with Gunicorn as the WSGI server and put Nginx in front of it as a reverse proxy.

Where to go after this course

  • Official Python tutorialThe Python documentation's own tour of the language, useful as a second explanation of anything that did not click here.
  • Pandas courseThe usual next step if you want to use Python for data analysis.
  • SQL courseLearn the queries that Flask-SQLAlchemy and pandas generate for you.
  • Python interview questionsPractise explaining data types, generators, decorators, and the GIL out loud before an interview.

Frequently Asked Questions

Which Python version should I install?

Install the newest stable release from python.org, which is Python 3.14. Python 3.13 is still in bugfix support and runs everything in this course. Python 3.10 reaches end of support in October 2026, so avoid starting on it. The downloads page lists each version's support status and end date.

Should I type python or python3?

On Linux and macOS, use python3. On many systems the plain python command is missing or points somewhere unexpected. On Debian and Ubuntu, the python-is-python3 package makes python point to Python 3 if you prefer the shorter name. The Windows installer sets up python and the py launcher instead.

Do I need a virtual environment?

Not for the standard library lessons. You do need one as soon as you pip install a package such as requests, Flask, or NumPy, because recent Debian and Ubuntu releases refuse system-wide pip installs with an "externally-managed-environment" error. Create and activate one per project:

bash
python3 -m venv .venv
source .venv/bin/activate

Should I learn Flask or Django?

This course uses Flask because it is small enough that you can see every piece: routes, templates, the database layer, and the WSGI server. Django bundles an ORM, an admin site, and authentication, which saves time on larger applications but hides more of the mechanics. Learning Flask first makes Django's choices easier to understand later.

Can Python use more than one CPU core?

The standard CPython build has a global interpreter lock (GIL), so only one thread runs Python code at a time. Threads still help with I/O-bound work such as network calls. For CPU-bound work, use multiprocessing, which runs separate interpreter processes. Python 3.14 also makes the optional free-threaded build, which removes the GIL, an officially supported option.

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with 15+ years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)