PYTHON · PYTHON FOR EVERYONE · CHAPTER 1

What is Python?

Understand what kind of language Python is, install version 3.14 and set up your work environment.

11 min readCourse: Python for EveryoneLevel: beginner
AGLE methodSelf-studyAll the chapter text, at your own pace.

From point A to point B

Point A: you keep hearing that Python is the tool for network automation, but you don't know exactly what it is or how to get started. Point B: by the end of this chapter, you'll understand what kind of language Python is, have Python 3.14 installed and verified on your machine, create a virtual environment and find your way around the interactive interpreter.

This course is based on the book “Python para todos”, written for Python 2.5. Everything here is updated to Python 3.14 and tested with the real interpreter.

What Python is and where it comes from

Video for this topic · in Spanish

Python is a general-purpose programming language. Guido van Rossum created it in the early 1990s at CWI, a research center in the Netherlands. It started as a successor to another language called ABC.

The name has nothing to do with the snake. Van Rossum was reading the scripts of “Monty Python's Flying Circus”, the British comedy series, and wanted a short, slightly mysterious name. The first public release came out in February 1991.

Its hallmark is readability. Python code looks a lot like a plain-English description of what you want to do. That clarity is a design decision: code gets read far more often than it gets written.

5 traits that define it

Video for this topic · in Spanish

When people describe Python, they usually say it's interpreted, dynamically typed, strongly typed, cross-platform and multi-paradigm. Let's see what each label means.

Interpreted, with bytecode in between

A compiled language like C is translated once into machine code, and the processor runs it directly. An interpreted language needs a program in the middle, the interpreter, which reads your code and runs it. Compiled code tends to run faster; interpreted code wins on flexibility and portability.

Python sits somewhere in between. Before running, it translates your code into bytecode, an intermediate language its virtual machine understands. When you import a module, Python saves that bytecode in .pyc files so it doesn't have to repeat the translation next time.

$ python3 main.py          # main.py imports the utils.py module
hello
$ ls __pycache__
utils.cpython-314.pyc

The file name includes the implementation and the version (cpython-314). That way, bytecode from different Python versions can live side by side without conflicts. The script you run directly isn't cached; only the modules you import are.

Python 3.14 update. The original book talked about .pyc and .pyo files next to the source code. In Python 3, bytecode is stored in the __pycache__ folder (PEP 3147), and since Python 3.5 .pyo files no longer exist: optimized bytecode uses names like module.cpython-314.opt-1.pyc (PEP 488).

Dynamically typed

In Python, you don't declare a variable's type. The type belongs to the value, and Python figures it out at run time. The same variable can point to a number first and to a piece of text later.

Strongly typed

Dynamic typing doesn't mean Python mixes types however it likes. If you try to add text and a number, it stops with an error instead of guessing what you meant. To combine them, you have to convert one of them explicitly.

# Dynamic typing: the variable has no declared type; the value does
port = 22
print(type(port))
port = "ssh"
print(type(port))

# Strong typing: Python won't mix text and numbers on its own
vlan = "10"
try:
    print(vlan + 5)
except TypeError as error:
    print("TypeError:", error)
print(int(vlan) + 5)
print(vlan + str(5))
<class 'int'>
<class 'str'>
TypeError: can only concatenate str (not "int") to str
15
105

Look at the last 2 lines. Converting the text to a number gives 15; converting the number to text gives “105”. Python makes you decide, and that prevents silent bugs.

Cross-platform

There are Python interpreters for Linux, Windows, macOS and other Unix-like systems. If you don't use features specific to one system, the same program runs on all of them unchanged.

Multi-paradigm

Python is object-oriented: you can model a problem with classes and objects that interact with each other, such as a Router object with its interfaces. It also supports procedural programming (step-by-step instructions) and functional programming. You pick the style that best fits each task.

Why learn Python, especially for networking

Video for this topic · in Spanish

Python's syntax is short and consistent. That's why the official documentation itself recommends it as a first language: you focus on solving the problem, not on fighting the syntax. Even so, it takes practice, like any language.

Its other big strength is the ecosystem. The standard library ships modules for JSON, IP addresses, sockets, HTTP and much more. On top of that, the PyPI index hosts hundreds of thousands of community packages.

On the network programmability path, Python is the everyday work tool. You'll use it to read device inventories and query REST APIs that respond in JSON. You'll also process syslog logs and generate configurations from templates.

Does it have limits? Yes. It isn't the best choice for low-level programming, like a driver, or for tasks where every microsecond counts. In those cases, it's combined with C, C++ or Rust.

Fact. Python 3.14 was released on October 7, 2025 and will get security fixes until around October 2030 (PEP 745). Python 2 reached end of life on January 1, 2020: if you find code with print "hello", it's Python 2 and needs to be ported.

Python implementations

Video for this topic · in Spanish

“Python” is the language. The program that runs it is an implementation, and there are several:

  • CPython is the reference implementation, written in C. It's the one you download from python.org and the one we use throughout the course. When someone says “Python”, they almost always mean this one.
  • PyPy is an interpreter written in a subset of Python that includes a JIT compiler. In 2026, it's compatible with Python 3.11.
  • Jython runs on the Java virtual machine and lets you use Java libraries. It still implements Python 2.7, so it isn't suitable for this course.
  • IronPython runs on .NET. Its 3.4 release is based on Python 3.4, far behind CPython.

You can ask Python which implementation and version you're using:

>>> import sys
>>> sys.implementation.name
'cpython'
>>> sys.version_info[:2]
(3, 14)

Install Python 3.14

Video for this topic · in Spanish

First, check whether you already have Python. Open a terminal and type:

$ python3 --version
Python 3.14.6

On Windows, try python --version or py --version. If you see version 3.14 or later, you're ready to continue. If nothing shows up or the version is old, install it for your system.

Windows: the Python install manager

Starting with Python 3.14, the recommended method on Windows is the Python install manager. It's a small app that installs and manages one or more Python versions. You have 3 ways to get it:

  • From the Microsoft Store: search for “Python install manager”, install it and type python in a terminal.
  • With WinGet, from PowerShell.
  • By downloading the MSIX package from python.org/downloads and double-clicking it.
$ winget install 9NQ7512CXL7T -e --accept-package-agreements --disable-interactivity
$ py install --configure -y      # optional: review the configuration
$ py list                        # installed versions
$ py install 3.14                # install a specific version
$ py -V:3.14 --version           # run that version

With the manager, python and py launch the default version, which is the latest stable release unless you change it. py also accepts subcommands such as install, list and uninstall.

Python 3.14 update. The original book only mentioned a classic Windows installer. That full installer still exists, but it's deprecated as of Python 3.14 and won't be released for Python 3.16 or later. The old py.exe launcher is also replaced by the install manager.

macOS

macOS ships a python3 in /usr/bin, but it's an old version installed by the Xcode tools. Don't modify or delete it. You have 2 options:

  • The official installer (.pkg) from python.org. It creates the /Applications/Python 3.14 folder with IDLE. When it finishes, double-click Install Certificates.command to install the root SSL certificates.
  • Homebrew, a community package manager: brew install python@3.14. The Python team doesn't maintain it, but it's widely used.

Linux

Most distributions already include Python 3. Use your distribution's package manager. Keep in mind that the version may be older than 3.14: Ubuntu 24.04, for example, ships Python 3.12.

$ sudo apt install python3 python3-venv     # Debian and Ubuntu
$ sudo dnf install python3                  # Fedora and RHEL

On Debian and Ubuntu, the venv module comes in a separate package, python3-venv; without it, you can't create virtual environments. On Linux and macOS, always use the python3 command: on many systems, python doesn't exist or points to another version.

Virtual environments with venv

Video for this topic · in Spanish

A virtual environment is a folder with its own Python and its own packages. It keeps each project's dependencies isolated. That way, installing a library for project A doesn't break project B.

The convention is to create it in the project folder with the name .venv:

$ mkdir network-automation && cd network-automation
$ python3 -m venv .venv
$ source .venv/bin/activate        # Linux and macOS
(.venv) $ python --version
Python 3.14.6
(.venv) $ deactivate

On Windows, activation is different: .venv\Scripts\activate.bat in cmd or .venv\Scripts\Activate.ps1 in PowerShell. The (.venv) prefix in the prompt reminds you that the environment is active.

Since Python 3.13, venv creates a .gitignore file inside the environment so Git ignores it. Don't commit the environment to your repository: if it breaks, delete it and create it again.

The interactive interpreter (REPL)

Video for this topic · in Spanish

There are 2 ways to run Python. One is to write a program in a file and run it; you'll see it in chapter 2. The other is the interactive session, also called the REPL (read-eval-print loop): you type a line, and Python runs it and answers right away.

To open it, type python3 with no arguments (python or py on Windows):

$ python3
Python 3.14.6 (main, Jul 18 2026, 17:01:31) [Clang 22.1.3 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + 3
5
>>> exit

The first line shows the exact version. The 3 signs >>> are the prompt: Python is waiting for your code. To leave, type exit or press Ctrl+D (Ctrl+Z and Enter on Windows).

Since Python 3.13, the REPL is much more comfortable:

  • It edits multi-line blocks and brings them back whole from the history.
  • exit, quit and help work without parentheses.
  • F1 opens help, F2 browses the history without the prompts and F3 turns on paste mode for long blocks.
  • Prompts and error messages show up in color.

Python 3.14 adds syntax highlighting as you type and module autocompletion: type import js, press Tab and it suggests json. If your terminal doesn't play well with colors, set the NO_COLOR environment variable; to go back to the basic REPL, set PYTHON_BASIC_REPL.

Use the REPL as a calculator and a lab. Whenever you're unsure how something behaves, try it there before you write it into your program.

Tools for writing code

Video for this topic · in Spanish

IPython and Jupyter

IPython is an enhanced interactive interpreter. You install it with pip inside your virtual environment. One of its most useful features is the ? operator: type it after a name and you'll see its documentation.

(.venv) $ python -m pip install ipython
(.venv) $ ipython
In [1]: len?
Signature: len(obj, /)
Docstring: Return the number of items in a container.
Type:      builtin_function_or_method

IPython also autocompletes names, methods and attributes with Tab. It's the engine behind Jupyter, which brings this experience to the browser as notebooks with code, results and text. Notebooks are very handy for exploring network data, such as interface counters or API responses.

Editors and development environments

  • IDLE comes with Python. It's basic, but it's enough for your first steps. On some Linux distributions, it's installed separately.
  • Visual Studio Code is a free editor. With the Python extension, you get autocompletion, a debugger, error detection and support for virtual environments and Jupyter notebooks.
  • PyCharm is an IDE dedicated to Python, with advanced refactoring and debugging tools.
  • If you live in the terminal, vim and emacs are still valid options with the right plugins.
Python 3.14 update. The original book recommended PyDEV, SPE, Eric and BOA Constructor, and explained how to install PyReadline for autocompletion on Windows. Those recommendations are outdated today: the standard REPL already autocompletes and adds color, IPython works the same on every system and the most popular editors are VS Code and PyCharm.

Don't waste time hunting for the perfect tool. Pick one, learn its basic shortcuts and switch only if something slows you down.

Key takeaways

  • Python is interpreted, with intermediate bytecode, dynamically typed and strongly typed.
  • CPython is the reference implementation; it's the one you use in this course.
  • On Windows, you install Python 3.14 with the Python install manager and the py command.
  • On Linux and macOS, use python3 and check the version with python3 --version.
  • Every project deserves its own virtual environment: python3 -m venv .venv.
  • The Python 3.14 REPL adds color, autocompletes and is your test lab.

In chapter 2, you'll write your first program in a file and run it like any other system command.

AGLE methodInstructor-guidedThe class videos.

Class videos

The videos are in Spanish. The translation of the videos is in development.

Each topic in the chapter has its own video, 2 to 3 minutes long, with narration and captions. Tap a card and the video opens right here, over the page; use the Close button or the Esc key to go back to where you were.

The narration uses Jesús Espinoza's voice, recreated with AI. The script and animations are by The House of Routing. When you play a video, it loads from YouTube (no cookies until you open it). See the full playlist on YouTube.

AGLE methodContinuous assessmentQuestions to measure your progress.

Challenge

Answer before you open the solution.

1. What does "10" + 5 return in Python, and why?

A TypeError. Python is strongly typed: it doesn't turn text into a number on its own. You need to write int("10") + 5 or "10" + str(5), depending on what you want.

2. You find a __pycache__ folder with .pyc files. What are they?

Cached bytecode. Python translates imported modules into bytecode and stores it there so it doesn't have to redo the work. You can safely delete the folder: it rebuilds itself.

3. On Windows with Python 3.14, which command installs a specific Python version?

py install 3.14. It's a subcommand of the Python install manager. py list shows the installed versions.

4. What's a virtual environment for?

To isolate each project's dependencies. Every environment has its own Python and packages, so projects don't step on each other.

5. You see print "hello" in a script. What does that tell you?

That it's Python 2 code. In Python 3, print is a function and you write print("hello"). Python 2 has been unsupported since 2020.

Official resources

Source and credits. This course is based on the book Python para todos by Raúl González Duque, published under the Creative Commons Attribution 2.5 Spain license. The original book was written for Python 2.5. Jesús Espinoza, with AI assistance, brought it to Python 3.14: he rewrote every chapter in his own words, replaced the examples with networking cases, updated the syntax and the modules that no longer exist, fixed errors in the original and tested all the code with Python 3.14.6 against the official documentation.

Navigate