Guide Python Beginner

Installation of Python

How to install Python on Windows, Linux, and macOS, choosing an IDE, the four ways to run Python code, the CPython execution pipeline, bytecode and the PVM, PEP 8 coding standards, your first program, real-world DevOps examples, and common installation mistakes.

10 min read

1.1 Installing Python

Getting Python onto a machine is the prerequisite for everything else in this guide — the steps differ slightly per OS but the goal is the same: a working python3 command on your PATH.

Windows

Download the installer from python.org and run it. Critically, check “Add python.exe to PATH” during setup — this is the single most common installation mistake (see Section 1.19).

# After installation, verify in Command Prompt or PowerShell:
C:\> python --version
Python 3.12.3

Linux

Most modern distributions ship with Python 3 pre-installed. If not, install via the system package manager.

# Debian/Ubuntu
$ sudo apt update && sudo apt install python3 python3-pip

# RHEL/CentOS/Fedora
$ sudo dnf install python3 python3-pip

macOS

macOS ships with an older system Python; installing a current version via Homebrew is the standard approach to avoid touching the system copy.

$ brew install python3

Verifying Installation

The same two commands work identically across all three operating systems once Python is installed and on the PATH:

$ python3 --version
Python 3.12.3

$ python3 -c "print('It works')"
It works

PATH Configuration. The PATH is the list of directories the OS searches when you type a command name. If Python’s install directory isn’t on PATH, typing python3 gives “command not found” even though Python is correctly installed. How to fix it: add Python’s install/Scripts directory to the PATH environment variable (Windows: System Properties → Environment Variables; Linux/macOS: export PATH in ~/.bashrc or ~/.zshrc).

1.2 IDEs and Editors

An IDE isn’t required to write Python (any text editor plus a terminal works), but a good one speeds up everyday work significantly through autocompletion, debugging, and inline error checking.

VS Code: A free, lightweight, highly extensible editor. With the Python extension installed it gets linting, debugging, and Jupyter notebook support — the most commonly used editor for Python in industry today.

PyCharm: A full-featured, Python-specific IDE (JetBrains) with deep refactoring tools, built-in test runners, and database tools. The free Community edition covers most day-to-day needs; the Professional edition adds web-framework support.

Jupyter Notebook: A browser-based, cell-by-cell execution environment — you run one chunk of code at a time and see its output inline. The standard tool for data science and exploratory analysis, less suited to production application code.

IDLE: Python’s own built-in, no-install-needed editor and shell. Minimal features, but useful for a completely clean testing environment or on a machine where you can’t install anything else.

Vim: A terminal-based, keyboard-driven editor. Popular for editing files directly on remote servers over SSH — exactly the situation a DevOps engineer is in constantly, where a full GUI IDE isn’t available.

1.3 Running Python Programs

There are four common ways to execute Python code, each suited to a different situation:

Interactive Shell

Typing python3 with no arguments drops you into a REPL (Read-Eval-Print Loop) where each line executes immediately — fast experimentation for testing a one-liner or checking a library’s behavior without creating a file.

$ python3
>>> 2 + 2
4
>>> exit()

Script Execution

The standard way to run a real program: save code in a .py file and pass it to the interpreter.

$ python3 hello.py
Hello, World!

Command Line:

The -c flag runs a short snippet of code passed directly as a string argument — useful in shell scripts or one-off checks without creating a file.

$ python3 -c "import sys; print(sys.version)"
3.12.3 (main, Mar 3 2026, 12:15:18) [GCC 13.3.0]

IDE Execution:

Most IDEs (VS Code, PyCharm) provide a “Run” button that executes the current file behind the scenes using the same python3 command shown above, and displays the output in an integrated panel.

1.4 Python Execution Process

Understanding what actually happens between running python3 hello.py and seeing output demystifies a lot of Python’s behavior and error messages.

flowchart LR A["Source Code\n(hello.py)"] --> B["Compiler\n(compiles to bytecode)"] B --> C["Bytecode\n(.pyc file)"] C --> D["Python Virtual Machine\n(interprets, executes line by line)"] D --> E["Output\n(program result)"]

Source Code. The plain-text .py file you write, in Python syntax. This is the only artifact a developer directly edits — everything downstream is generated automatically.

Compilation to Bytecode. Bytecode is a lower-level, platform-independent instruction set that’s much faster for the interpreter to execute than re-parsing raw text every time. This step happens automatically and invisibly whenever you run a script — see Section 1.13 for what the bytecode actually looks like.

Python Virtual Machine. The runtime engine that reads bytecode instructions one at a time and carries them out. This is covered in full in Section 1.14.

Execution Flow. Putting it together: source (.py) → compiled to bytecode (in memory, and cached to disk as .pyc) → the PVM interprets that bytecode → your program’s actual output appears. This entire pipeline runs every time you execute python3 somefile.py.

1.5 Python Interpreter

Python Interpreter

Role of Interpreter:

The program that reads your Python source, compiles it to bytecode, and runs that bytecode. This matters because “Python” the language is really a specification — multiple different interpreters implement it, each with different trade-offs.

flowchart LR CP["CPython\nWritten in C\nThe reference implementation"] PP["PyPy\nWritten in RPython\nJIT-compiled — much faster"] JY["Jython\nRuns on the JVM\nintegrates with Java libraries"] IP["IronPython\nRuns on .NET CLR\nintegrates with .NET/C#"]

CPython:

The reference implementation, written in C. When someone says “Python” without qualification, they almost always mean CPython — it’s what you get from python.org, and what this entire guide assumes.

>>> import sys
>>> sys.implementation.name
'cpython'

PyPy:

An alternative implementation with a Just-In-Time (JIT) compiler, which can make long-running, compute-heavy programs significantly faster than CPython. Trade-off: some C-extension libraries aren’t fully compatible.

Jython:

Runs Python on the Java Virtual Machine, letting Python code import and use Java libraries directly — useful in a Java-heavy enterprise environment. It has not kept pace with modern Python 3 features.

IronPython:

Runs Python on the .NET Common Language Runtime (CLR), giving access to .NET/C# libraries — the Jython equivalent for the Microsoft ecosystem.

1.6 Bytecode

Bytecode

What Is Bytecode?

A low-level, platform-independent set of instructions that the Python Virtual Machine executes — an intermediate step between your readable source code and actual execution. It’s faster for the PVM to run than reparsing text, and it’s portable across any machine with a compatible CPython version. The built-in dis module disassembles a function into its bytecode instructions:

>>> import dis
>>> def add(a, b):
...     return a + b
...
>>> dis.dis(add)
  1           0 RESUME                   0

  2           2 LOAD_FAST                0 (a)
              4 LOAD_FAST                1 (b)
              6 BINARY_OP                0 (+)
             10 RETURN_VALUE

__pycache__:

A folder Python automatically creates next to your source files to cache compiled bytecode (.pyc files), named after the interpreter version (e.g. module.cpython-312.pyc). If the source hasn’t changed since the cache was written, Python skips recompiling it, speeding up subsequent runs — most noticeable when importing large modules repeatedly.

$ python3 -c "import mymodule"
$ ls __pycache__/
mymodule.cpython-312.pyc

Advantages

  • Faster startup on subsequent runs (no need to recompile unchanged source)
  • Platform-independent — the same .pyc format works across OSes for a given Python version
  • Enables the interpreter to catch syntax errors before any code actually executes

1.7 Python Virtual Machine (PVM)

What Is PVM?

The runtime engine at the heart of CPython that actually executes bytecode instructions. It’s the reason Python code is portable — the PVM, not your code, deals with the underlying OS and hardware differences.

How PVM Executes Bytecode?

The PVM runs a loop that fetches one bytecode instruction at a time (like LOAD_FAST or BINARY_OP, as seen in Section 1.13’s dis output), executes it against an internal stack of values, and moves to the next instruction — continuing until the program ends or raises an unhandled exception.

1.8 Python Compilation vs Interpretation

Compilation: Translating source code into another form before execution. In compiled languages like C, that form is native machine code specific to one CPU architecture, produced by a separate build step.

Interpretation: Executing source code directly, statement by statement, without a separate build step producing a standalone executable. Purely interpreted languages re-parse and evaluate the source text every run.

Hybrid Model: What Python actually does: it’s neither purely compiled nor purely interpreted — it compiles source to bytecode (a fast, one-time step, cached in __pycache__), then interprets that bytecode via the PVM every run. This hybrid approach gives Python the fast edit-run cycle of an interpreted language while still getting a speed boost from not re-parsing raw text on every execution.

1.9 Coding Standards

Consistent style matters more in Python than most languages, since indentation is syntactically meaningful — following a shared standard also makes code far easier for teammates to read and review.

PEP 8: Python’s official style guide, covering indentation, naming, line length, and more. Consistent style across a codebase (and across the whole Python community) reduces friction when reading other people’s code. In practice: 4 spaces per indentation level, a max line length of 79–99 characters depending on team convention, and tools like flake8 or black can auto-check or auto-format code against it.

# PEP 8 compliant
def calculate_total(price, quantity):
    return price * quantity

# Not PEP 8 compliant (inconsistent spacing, bad indentation)
def calculateTotal(price,quantity):
  return price*quantity

Naming Conventions

ElementConventionExample
Variables/functionssnake_caseuser_count, get_data()
ClassesPascalCaseUserAccount
ConstantsUPPER_SNAKE_CASEMAX_RETRIES
Private (convention only)_leading_underscore_internal_cache

Comments: # starts a comment that runs to the end of the line, used to explain WHY code does something non-obvious — not to restate what the code already says.

# Retry 3 times because the API occasionally times out under load
for attempt in range(3):
    ...

Documentation: Docstrings ('''triple-quoted strings''') placed as the first statement in a function, class, or module, describing what it does. Tools like help() and IDEs display docstrings automatically, and documentation generators (Sphinx) extract them to build reference docs.

def add(a, b):
    """Return the sum of a and b."""
    return a + b

>>> help(add)
Help on function add in module __main__:

add(a, b)
    Return the sum of a and b.

1.10 Common Mistakes

Nearly every beginner hits these same three issues in their first week — knowing them in advance saves the debugging time.

Installation Issues: What goes wrong: installing Python but the installer silently fails, or an old bundled version shadows the new one. How to verify: always run python3 --version immediately after installing, before writing any code.

PATH Issues: What goes wrong: Python installs correctly, but python3 (or python) isn’t recognized in the terminal because its directory isn’t on the PATH (see Section 1.8). Symptom: 'python3' is not recognized as an internal or external command (Windows) or command not found (Linux/macOS). Fix: reinstall with the “Add to PATH” option checked, or manually add the install directory to PATH.

Version Mismatch: What goes wrong: a machine has both Python 2 and Python 3 installed, and python resolves to the wrong one (often still Python 2 on older Linux/macOS systems). Fix: always use the explicit python3 command rather than python when both might be present, and check with python3 --version before running anything version-sensitive.

1.11 Interview Questions

Beginner Interview Questions — common opening questions used to check foundational understanding before moving to coding exercises:

  • What is Python, and what type of language is it (interpreted/compiled, dynamically typed)?
  • What is the difference between Python 2 and Python 3?
  • What is PEP 8, and why does it matter?
  • What is the difference between a compiled language and an interpreted language?
  • What is CPython, and how does it relate to “Python” the language?
  • What is bytecode, and where is it stored?

Frequently Asked Concepts — beyond factual recall, these conceptual questions test whether you understand WHY, not just WHAT:

  • Why is Python considered dynamically typed? Give an example.
  • Explain the role of the Python Virtual Machine in program execution.
  • Why might a team choose Python over Bash for a DevOps automation task?
  • What is __pycache__, and why does Python create it?
  • What are some real-world use cases of Python in cloud/DevOps environments?

Quick Interview Answer

“Python is a high-level, interpreted, dynamically-typed, general-purpose language created by Guido van Rossum, first released in 1991. It compiles source to bytecode and runs that bytecode through the Python Virtual Machine (CPython being the reference implementation) — a hybrid model that gives it a fast edit-run cycle. It’s popular in DevOps because of its readable syntax, huge standard library, and mature ecosystem — boto3 for AWS, paramiko for SSH, and being the language Ansible itself is built on.”

Common Mistakes

  • Assuming python and python3 are always the same command — on systems with both Python 2 and 3 installed, they can resolve differently.
  • Forgetting to check “Add to PATH” during a Windows install, then being confused why the command isn’t recognized.
  • Confusing “interpreted” with “not compiled at all” — Python actually compiles to bytecode first; it’s a hybrid model, not pure interpretation.

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form