Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This installment is a practical introduction to Python fundamentals: expressions and data types, control flow, functions, collections, modules, errors, and a first look at classes. The title “Modern Python (Part 1)” does not identify a specific author, book, course, or verified syllabus, so this article uses the official Python tutorial as its guide—not as a claim about an existing series.

The official tutorial is aimed at people who are new to Python but already understand basic programming. If you are entirely new to programming, expect to spend extra time on concepts such as variables, conditions, loops, and functions as you work through the examples. The examples here follow the Python 3.14.7 documentation; check the documentation for the version you install.

Start by running small pieces of Python

Python can be explored interactively in an interpreter, where you enter an expression and see its result immediately. You can also save code in a file and run it as a script. The interactive approach is useful when learning: try an expression, change it, and observe what happens before building a larger program.

The Python interpreter and standard library are freely available in source or binary form for major platforms, and the official tutorial encourages hands-on practice. The tutorial can also be read offline. See Using the Python Interpreter for interpreter and script details, and Whetting Your Appetite for the official introduction to Python and its availability.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a foundation with expressions and data types

An expression combines values and operations to produce a result. For example, 3 + 4 evaluates to 7, while "Py" + "thon" produces "Python". Python uses different types of values for different purposes: numbers for arithmetic, strings for text, and Boolean values True and False for conditions.

Names let you keep and reuse values:

language = "Python"
version = 3.14
print(language, version)

Assignment binds a name to a value; it is not a declaration that fixes the name to one type. As you experiment, try combining values of the same type, then inspect what happens when an operation does not make sense for the values you chose.

Use control flow to make decisions and repeat work

Control flow determines which statements run and how often. An if statement chooses a branch based on a condition; a for loop processes items in a sequence or other iterable; a while loop repeats while its condition remains true.

temperature = 18

if temperature < 20:
    print("Bring a jacket")
else:
    print("A light layer may be enough")

Python uses indentation to mark the statements belonging to a block. Keep indentation consistent, and check the condition and loop boundaries carefully: a mistaken condition can select the wrong branch or keep a loop running longer than intended.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Package reusable operations in functions

A function gives a name to a task that can be called again. It can accept inputs as parameters and return a result, keeping a program easier to test and understand.

def greeting(name):
    return f"Hello, {name}!"

message = greeting("Sam")
print(message)

Prefer functions that do one clear job. Use parameters for information that varies, and return a value when the caller needs a result. This makes it easier to reuse the logic without copying and editing the same statements in multiple places.

Choose a collection that fits the data

Collections group related values. Lists preserve order and can be changed; tuples preserve order but are typically used for fixed groupings; dictionaries associate keys with values; sets hold distinct items without treating their order as the main feature.

tasks = ["read", "practice"]
tasks.append("review")

settings = {"theme": "dark", "font_size": 14}
print(settings["theme"])

Use a list when you need an ordered collection that may change, and a dictionary when values are best retrieved by a meaningful key. The official tutorial develops these structures alongside loops and other control-flow tools, so practice iterating over a collection as well as creating one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Move reusable code into modules

A module is a Python file containing definitions and statements that can be imported by another program. Modules help divide a larger task into files and let you reuse code without copying it into every script.

# greetings.py
def greeting(name):
    return f"Hello, {name}!"
# app.py
from greetings import greeting

print(greeting("Sam"))

Keep related functions together, give modules descriptive names, and import only what the program needs. The official tutorial’s Modules chapter explains importing and organizing code.

Handle errors deliberately with exceptions

Exceptions interrupt normal control flow when an error or other exceptional condition occurs. A try block marks code that may raise an exception; a matching except block handles a particular kind of exception. A finally block can perform cleanup whether or not an exception occurred.

try:
    quantity = int(input("How many? "))
except ValueError:
    print("Enter a whole number.")
finally:
    print("Input attempt finished.")

Catch exceptions you can respond to meaningfully, rather than hiding every failure with a broad handler. For the language’s exception model and syntax, consult the language reference entry for try.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Meet classes without making every program object-oriented

A class defines a kind of object by grouping data and behavior. It can be useful when a program needs several related values and operations to travel together, such as a task with a title, completion status, and method for marking it complete.

class Task:
    def __init__(self, title):
        self.title = title
        self.done = False

    def complete(self):
        self.done = True

Classes are one tool, not a requirement for every small script. Start with straightforward values and functions; introduce a class when it makes the relationships in the program clearer. The official tutorial’s Classes chapter continues from the basics.

Use the right Python documentation as you continue

The Python documentation separates an introductory tutorial, a language reference, and a library reference because they answer different kinds of questions. The tutorial is a guided feature tour, not a comprehensive manual. When you want to know exactly how syntax behaves, use the language reference; when you need a built-in or standard-library module, use the library reference. Python’s standard library covers a broad range of common tasks, but you do not need to learn it all at once.

For a practical next step, choose a small task, write it as a script, and break repeated work into functions. Then use the documentation when a feature or library call raises a question. The official tutorial is free; a beginner Python programming book is an optional alternative if you prefer learning from print, not a prerequisite.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.