Python

Course Description

Python is a free, open-source programming language created by Guido van Rossum. The syntax is simple, so Python code is easy to read and write, and it runs on Windows, macOS, and Linux. You can use it for anything from a ten-line script to a large application. In this course, we cover the basics of Python with a focus on network engineers. We start with installing Python and your first print function, work through data types, operators, loops, functions, and modules, and finish by connecting to a Cisco router with SSH and talking to REST APIs. That’s what you need to start using Python with networks, network devices, and APIs.

Course Highlights

In this course you will learn:

  • How to install Python and choose an IDE to write your code.
  • How to use variables and the main data types: numbers, strings, lists, tuples, and dictionaries.
  • How to format strings with f-strings, and how to split and slice strings and lists.
  • How to use arithmetic, assignment, comparison, logical, membership, identity, and bitwise operators.
  • How to control your code with if, elif, and else, and repeat it with while and for loops.
  • How to write reusable code with functions and modules, and how variable scope works.
  • How to install packages with PIP, read and write files, and handle errors with try and except.
  • How to convert JSON data to Python dictionaries and back.
  • How to connect to a Cisco IOS router through SSH with Paramiko, and to REST APIs with the requests library.

Presented to you by instructor Rene Molenaar, CCIE #41726

Course at a glance

  • 34 lessons, from your first print function to connecting to network devices and APIs.
  • Format: self-paced lessons with Python code examples you can run yourself, and video.
  • Last updated: October 2026.

Requirements

  • No programming experience required; we start from the beginning.
  • Basic computer skills.
  • A computer running Windows, macOS, or Linux to install Python on.

Course Schedule

What is Python?

Python is a general-purpose programming language. Guido van Rossum started it in the late 1980s and named it after the television show Monty Python, not the snake. Python runs on an interpreter, so you don’t have to compile your code first: you type a line, and it runs right away. The syntax is simple and readable, and there are thousands of packages on the Python Package Index (PyPI) that you can install with PIP. Python 2 was retired on January 1, 2020, so everything we do uses Python 3.

Why should network engineers care? The CLI is great for humans but not for repetitive work. Collecting show output from 50 routers or adding a VLAN to every switch by hand takes time, and it’s easy to make mistakes. With Python, you can connect to devices through SSH or an API, run commands, parse the output, and push configuration changes. Python is also the language behind tools like Ansible.

Who uses Python? Network engineers and DevOps engineers use it to automate their networks and servers. It’s also used for web development with frameworks like Django and Flask, for data analysis, for machine learning, and even on IoT devices with MicroPython. You won’t need all of that. In this course, we focus on the parts of Python that you need as a network engineer.

Python Learning Roadmap

This roadmap follows the course units. Each topic has a short explanation and links to the lessons where we cover it in detail.

Getting Started with Python

We start with an introduction to Python and the installation of Python 3 on Windows, macOS, or Linux, then run code in the interactive interpreter. You write your first lines with the print function, store values in variables, and add comments so you still understand your code six months from now. IDLE, which comes with the Python installer, is fine to start with; later on, an IDE like Visual Studio Code makes life easier with syntax highlighting, auto-completion, and a debugger.

Python Data Types

Every value in Python has a data type. Numbers can be integers, floats, or complex numbers. A string is a sequence of characters, and f-strings (since Python 3.6) are the easiest way to format them. Lists and tuples store multiple items: a list can be changed, a tuple is immutable. Dictionaries store key-value pairs, which is perfect for things like a hostname and its IP address.

User Input, Split and Slice

The input function pauses your program, asks the user for something like a hostname, and stores the answer as a string. The split method turns a string into a list, which is useful when you process CSV files or command output. With slicing, you take part of a string, list, or tuple by specifying a start, stop, and step.

Python Operators

Operators let you calculate, assign, and compare values. Arithmetic operators do the math, assignment operators store the result in a variable, comparison operators return True or False, and logical operators (and, or, not) combine multiple conditions. Membership operators check if an item exists in a string, list, or dictionary, and identity operators check if two variables point to the same object in memory. Bitwise operators work on binary numbers; you won’t need them often, but they can be handy for subnet calculations.

Conditions and Loops

With if, elif, and else, your code makes decisions based on conditions. Loops repeat code: a while loop runs as long as a condition is true, which is useful when you don’t know how many iterations you need. A for loop iterates over every item in a sequence, like a list of routers, and the break statement lets you stop early.

Functions, Scope and Modules

A function is a block of code that only runs when you call it. You can send it arguments and it can return data, so you don’t have to repeat the same code. Variables you create inside a function have a local scope; variables outside of it are global. Modules let you split your code into multiple files and import them, and PIP installs packages from PyPI so you can use code that others wrote.

Files, Errors and JSON

Real scripts read configuration files, parse log files, and save their results, so we use the open function to read, write, and append to files. When something goes wrong, for example a device that doesn’t respond, Python raises an exception; with try and except, your script handles it instead of crashing. JSON is the most common data format for APIs, and the json module converts it to Python dictionaries and back.

Connecting to Network Devices and APIs

This is where everything comes together. We use the Paramiko library to connect to a Cisco IOS router through SSH, run show ip route, and find the default route in the output; then we improve the script with a function, try and except, and retries. With the requests library, we send HTTP requests to REST APIs: one without authentication, one with query parameters, and the Cisco DNA Center API, where we authenticate to get a token first.

Frequently Asked Questions

Do network engineers need Python?

You don’t need Python to configure a network, but it saves a lot of time. With Python, you can automate repetitive tasks, collect information from many devices at once, and work with the APIs of controllers and network devices. Read our introduction to Python.

With AI writing code, is Python still worth learning?

Yes. AI tools can write a lot of code for you, but you still need to read that code, check if it does what you want, and fix it when it doesn’t. That’s hard to do when you don’t know the basics yourself, especially when a script makes changes to production devices. Python also remains the most common language for network automation tools and libraries. Read our introduction to Python.

Is Python on the CCNA exam?

Not really. The CCNA 200-301 covers automation and programmability concepts like REST APIs, JSON, and configuration management tools, but you won’t have to write Python code. Learning some Python still makes those automation topics much easier to understand. Learn more about network automation.

Is Python hard to learn?

No. Python has a simple syntax that is easy to read, and you can try code right away in the interpreter without compiling anything. You don’t need any programming experience: we start with the print function and build up from there. Start with the print function.

How long does it take to learn Python for network automation?

You can learn the basics, like variables, loops, and functions, in a few weeks if you practice a little every day. Writing your first useful script, for example one that logs in to a router with SSH and collects show output, usually takes a bit longer, because that’s where you combine everything. The fastest way to learn is to automate a small task from your own job instead of only doing exercises. Start with the print function.

What should I learn after the CCNA: Python or automation?

Python is a great next step after the CCNA, because it builds on the automation topics you’ve already seen. Start with the Python basics, then learn how to work with JSON and REST APIs, and try it out on a lab router. You can also study for the CCNP ENCOR and learn Python next to it. Read our introduction to Python.

Should I learn Python or Ansible first?

It depends on what you want to do. Ansible gets you results faster because you write YAML playbooks instead of code, so it’s a good start if you mostly want to push configurations. Python takes longer to learn, but you can automate anything with it, and it helps you understand how tools like Ansible work. Many network engineers learn the Python basics first and then pick up Ansible. Learn more about network automation.

How do I connect to a Cisco router with Python?

The easiest way is SSH with a library like Netmiko. Netmiko is built on top of Paramiko, a general SSH library, and it’s made for network devices: it knows how to log in, enter enable mode, and send commands to many vendors. With Paramiko alone, you handle things like prompts and paging yourself, which is more work but shows you what happens behind the scenes. Learn how to use Python SSH.

Ready to learn Python?

Get access to all 34 Python lessons and every other course on NetworkLessons.com.

Sign up

Already have an account? Log in