How to learn Python on Windows step by step

Last update: May 4th 2026
  • Properly configuring Python on Windows avoids problems with paths, aliases, and versions.
  • The interactive interpreter and .py files make it easy to test code and build real programs.
  • Python's syntax, dynamic typing, and mandatory indentation promote readable code.
  • Built-in help and online resources allow you to continue learning Python independently.

Learn Python on Windows

If you're trying to learn Python on Windows and don't know where to start , you're not alone. The most complicated part of getting into any programming language isn't usually the code itself, but rather figuring out the installation, the tools, and the initial tests. Between system paths, execution aliases, and different Python versions, it's easy to get frustrated before even writing your first `print()`.

This article provides a detailed, practical, and nuanced guide to learning Python on Windows from scratch: how to install it correctly, how to avoid common path problems, what the interpreter is, how to write and run programs, how to organize your code into modules, and how to continue learning with helpful resources . Everything is explained in clear and accessible language, without omitting any important concepts.

Why is it so hard to get started with Python (especially on Windows)?

Many people agree that the first major obstacle to learning Python isn't the syntax or programming concepts, but something much more basic: knowing where to click and what to install. Users like you tell very similar stories: they try to create a virtual environment to use an older version of Python, they mess with Windows settings, they uninstall Python following a tutorial, and suddenly the system stops recognizing any Python commands.

One of the most confusing aspects is the issue of paths and environment variables . Why do you have to check the "Add Python to PATH" box? What does it mean that Windows can't find the command? What exactly is the purpose of "Manage application execution aliases"? For someone who simply wants to run a couple of data analysis scripts , it might sound completely unnecessary and even absurd.

However, these initial minor complications have an explanation: Windows needs to know where the Python interpreter is installed to be able to run it from any command prompt. If that path isn't in the PATH environment variable, you'll see errors like "python is not recognized as an internal or external command." And if, in addition, Microsoft Store aliases are mixed with traditional installations, things get a bit more complicated.

The good news is that, once you get past this initial installation and configuration phase, Python is very user-friendly and flexible . That's why many companies (including Google) use it as an introductory programming language, and there are specific courses for beginners that take you step by step from "I have no idea" to writing useful and readable programs.

Installing Python on Windows without going crazy

To learn Python on Windows properly, the best approach is to install a current version of Python 3 from the official website or a reliable source, and avoid any older or mixed installations that may be present. This reduces many common conflicts.

When you run the Python installer on Windows, you'll see a key checkbox: "Add Python to PATH". It's highly recommended to check this box, as it automatically adds the interpreter's path to your system's environment variables. This means that when you open a command prompt (CMD or PowerShell), you can simply type `python` or `python3` without having to remember the installation folder.

Another point of confusion is the Windows "Manage application execution aliases" option . This feature allows you to associate certain commands (like python.exe) with applications installed from the Microsoft Store. When you use Python from the Store and also install another version from python.org, Windows might launch one or the other in an unpredictable way. To avoid problems, it's best to use a single, well-configured main Python 3 installation and review these aliases to prevent conflicting paths.

If you uninstall Python at any point while following a tutorial and the system then stops recognizing the command, don't panic: usually, simply reinstalling Python 3 and re-checking the box in your PATH environment variable will fix the problem. From then on, you should be able to create virtual environments, install libraries, and run your scripts normally.

What exactly is the Python interpreter and how to use it

One of the best ways to truly understand how Python works is to launch the interactive interpreter and write code directly in it. The interpreter is a program that reads your instructions line by line, executes them instantly, and displays the result. On Windows, this is usually done by opening PowerShell or CMD and typing:

Python or Python 3

If everything goes well, you'll see something like a header with the Python version, followed by an invitation symbol like >>> . This indicates that you're inside the interpreter and can start trying very simple things : assigning values, performing addition, manipulating strings, and so on.

For example, you could write something like: a = 6 and then, on the next line, simply put a . The interpreter will print the value stored in that variable, in this case 6. You can also redefine that variable without any problem, for example by making a = 'hello', and then use functions like len(a) to see how many characters the string has.

  How to remove washed-out colors and excessive brightness from HDR in Windows

This way of working is perfect for experimenting and answering quick questions like "what happens if I add a number to a list?" or "what happens if I concatenate a string with an integer?". If you try something that doesn't make sense, like 'hello' + 3, the interpreter will show you an error explaining what went wrong (for example, a TypeError indicating that you can't concatenate str with int). And if you make a mistake with the name and write a variable you never defined, you'll receive a NameError warning you that the identifier isn't defined.

When you want to exit the interpreter in Windows, you can use the combination CTRL+Z followed by Enter , or you can also type exit() or quit(). This will return you to the Windows command line and allow you to continue with other tasks, such as running scripts saved in .py files.

Writing your first program: .py files and running it on Windows

Besides experimenting in the interpreter, sooner or later you'll want to save your Python code in files to reuse, share, or run it with different arguments. Python programs are usually saved in files with the .py extension and are known as modules. For example, you can create a file called hello.py with any decent text editor (VS Code, Notepad++, etc.).

Within that file, you can write a small program that receives an argument from the command line and uses it, for example:

importsys
def main ():
    print('Hello,', sys.argv)
if __name__ =='__main__':
    Main()

In this scheme, you import the sys module to access sys.argv , which is the list of arguments you pass to the program from the console. The first element (index 0) is the script name, and from index 1 onwards, the values ​​you specified appear. The main() function prints a greeting followed by the argument you pass it.

To run this file on Windows, open a terminal, navigate to the folder where you saved hello.py (using the `cd` command), and type something like: `python hello.py Ana` . If everything is configured correctly, you will see the message "Hello, Ana" on the screen. This simple example already allows you to understand how Python interprets a .py file from top to bottom , how to import modules, and how to execute the main logic with the commonly used pattern `if __name__ == '__main__'`.

Python as a language: dynamic, interpreted, and flexible

Python is a dynamic, interpreted, and very flexible language . This means that you don't declare variable types rigidly like in Java or C++: you don't have to specify whether something is int, string, or bool when defining it; you simply assign a value, and the interpreter handles the type at runtime.

This flexibility makes the code shorter and, in many cases, easier to read and write . You can use the same variable `a` to store first a number and then a string, and Python won't complain as long as the operations you perform make sense. However, you do forgo compile-time type checking, so some errors are only discovered when execution reaches that specific line.

For example, if you have a `main()` function that, in a certain case, calls another function misspelled (such as `repeeeet` instead of `repeat`), Python doesn't detect the error until it reaches that line at runtime and tries to invoke the incorrect name. Until that section of code is executed, the program may appear to work perfectly. The same applies to a variable that was never initialized: only when an attempt is made to read its value does the interpreter throw a `NameError`.

In the world of Python 3 , "type hints" were added , which allow you to annotate the arguments and return values ​​of functions with expected types, for example, `def is_positive(n: int) -> bool:`. These annotations are completely optional, but they allow advanced editors like VS Code or static analysis tools to check your calls and alert you if something doesn't match the indicated type.

While this article doesn't delve deeply into type suggestions, it's worth knowing that they exist and that more and more modern Python projects are adopting them. If you want to develop robust code at scale, they're a very useful tool, especially in teams where several people work on the same modules.

Functions in Python: docstrings, operators, and best practices

In Python, functions are defined with the keyword `def` , followed by the name, the parameters in parentheses, and a colon. The function body is indented with spaces. A typical example would be a function that repeats a string several times and, optionally, adds exclamation marks.

Conceptually, something like this could be a `repeat(text, exclamation)` function that creates a result by concatenating the `text` argument multiple times. Inside, you could use the `+` operator to join strings or the `*` operator to repeat them a certain number of times. For example, `'hello' * 3` produces `hellohellohello'`, while `'-' * 10` generates a kind of hyphen: `'———-'`.

In terms of performance, it's often said that using the * operator to repeat strings can be more efficient than concatenating them multiple times with +, because the size of the result is calculated only once instead of increasing incrementally. In small, learning programs, you'll barely notice this, but it's worth knowing because it's part of the language's design.

  Complete Guide to Windows Server: What It Is, What It's Used For, and Its Versions

Another interesting feature is docstrings , documentation strings that can be placed at the very beginning of a function definition. They are usually written with triple quotes ("" ... "") to allow for multiple paragraphs, and they explain what the function does, what arguments it receives, and what it returns. These descriptions are what `help()` will display later when you want to view your function's documentation.

Within a function, the variables you declare are local to that function, meaning they don't affect variables with the same name outside of it or in other functions. The value you want to return to the caller is specified with the `return` statement, which can be followed by the data to be returned. If you don't use `return` or call the function without a value, it returns `None`.

A very common pattern is to define several auxiliary functions and, near the end of the file, create a main() function that orchestrates the use of the others. Then, at the bottom, you place the typical if __name__ == '__main__': main() block, which is responsible for invoking that main function only when the file is executed directly, and not when it is imported as a module from elsewhere.

The importance of indentation in Python (and why to avoid tabs)

One of the features that most surprises those coming from other languages ​​is that indentation in Python is not decorative; it's syntax . Curly braces {} are not used to delimit blocks of code; instead, the indentation level is used: all lines that share the same block (a function, an if statement, a loop, etc.) must have exactly the same indentation.

If a single line within a block contains a different number of spaces , the interpreter will treat it as a syntax error. This is why it's so important to configure your editor to use spaces instead of tabs. Tabs can be interpreted with different widths in different editors or systems, leading to visual inconsistencies and errors that are very difficult to locate.

The official Python style guide (PEP 8) recommends using four spaces per indentation level . Some organizations, such as Google in their internal guidelines, use two spaces in certain contexts, but if you're just starting out, you should stick with four spaces, which is the most widespread standard.

While it might seem strange at first that whitespace is so important, you'll appreciate it over time: it forces code to be properly aligned, improves readability, and prevents chaotic blocks filled with stray curly braces. If you're working on Windows with a good editor (Visual Studio Code, for example), simply configure "insert spaces when pressing Tab" and perhaps enable automatic formatting adjustment to forget about it.

In short, paying attention to indentation from the start will save you from many silly mistakes and cryptic syntax messages . If you ever see an IndentationError, you'll know it's time to check the spaces at the beginning of your lines.

Variable names, namespaces, and modules

In Python, you don't declare the type of variables, so the names you choose are your best documentation . Using `a`, `b`, and `c` for everything is fine in a short example, but as your code grows, it's much more helpful to use names like `name`, `names`, `list_of_tuples`, `counter`, etc. This helps you remember what type of data you expect in each variable and reduces the number of basic errors.

The most common convention in Python for variables and functions is to use lowercase letters with underscores (called snake case). Some languages ​​prefer camelCase, and in cases where you're integrating with existing code that uses that style, it might make sense to mimic it. But if you're starting from scratch, the Python community generally recommends underscores to improve readability.

You should avoid using the language's own keywords (if, while, for, class, etc.) as variables, because the interpreter will flag it as a syntax error. However, it's also advisable not to reuse built-in function names like print, list, or str, as you would be overwriting them within your scope and could cause unexpected behavior. For example, if you define a variable called list, you won't be able to use the built-in function list() without first deleting or renaming your variable.

Regarding code organization, each .py file acts as a module with its own namespace . This means that if you have a file called utilities.py with a process() function, its fully qualified name would be utilities.process. This avoids conflicts with other process functions defined in different modules: each file maintains its own little world of identifiers.

When you import a standard module like `sys` with `import sys` , all its functions and variables become available under that prefix: `sys.argv`, `sys.exit()`, etc. There's also the form `from sys import argv, exit`, which lets you use `argv` and `exit()` directly without the prefix, but the version with the full name is generally recommended because it helps you understand where each symbol comes from and avoids confusion when using multiple modules simultaneously.

Python includes a fairly extensive standard library that is installed along with the interpreter. Some of the most commonly used modules are sys (system utilities and command-line arguments), re (regular expressions), os (file system access and operating system functions), among many others. This entire library is thoroughly documented on the official website, docs.python.org.

  How to reset the Windows 11 graphics driver without restarting the PC

Runtime errors and how to learn from them

Due to Python's dynamic nature, many checks are postponed until each line is executed. This means you'll only see some errors at runtime : misspelled names, uninitialized variables, incompatible types, and so on. It might be frustrating at first, but you'll soon get used to reading and understanding the error messages.

A typical example is a function that, within a specific branch of an if statement, calls a function name that doesn't exist. As long as that branch isn't executed, Python won't complain. The moment the erroneous line is reached, it will throw a NameError warning that the identifier is undefined. Something very similar happens if you compare a variable that was never initialized: the language will detect the problem as soon as it tries to evaluate that expression.

If you're coming from stricter languages, you might miss the compiler giving earlier warnings. Python takes a different approach: more freedom when writing code and less rigidity in compilation , in exchange for the programmer having to support that flexibility with tests, good tools, and, if desired, type annotations to reduce errors.

The positive aspect is that, precisely because of this agility, Python lends itself very well to learning through trial and error . The interactive interpreter, short scripts, and clear error messages allow you to quickly correct your code. Gradually, you'll develop the habit of running small parts of your program to ensure each piece works before complicating the next.

On Windows, a good strategy is to open a terminal, run your scripts, and if something goes wrong, carefully read the Python trace . In most cases, the message indicates not only the type of error but also the exact line and file where it occurred, which is very useful for quickly diagnosing and fixing the problem.

Built-in help and resources for further learning Python on Windows

In addition to official documentation and structured courses, Python includes help tools directly within the interpreter itself . Two of the most valuable for beginners are `help()` and `dir()`. Both allow you to explore what each function, module, or method does without leaving the Python environment.

For example, if you want to know how the built-in function `len()` works, you can type `help(len)` in the interpreter. Or, if you have imported the `sys` module with `import sys`, you can call `help(sys)` to read the documentation for that module, and `dir(sys)` to see the list of all its available attributes (variables, functions, etc.).

It's also possible to get help on methods of specific objects. For example, 'text'.split lets you access the split method of a string, and if you do `help('text'.split)` , you'll see a description of how to split strings into lists based on a separator. Similarly, `help(str.split)` will show you the same information, since it's the same method defined in the `str` class.

Similarly, you can use `help(list)` and `dir(list)` to discover how lists work in Python, see what methods they have (append, extend, sort, etc.), and then delve deeper into each of them with `help(list.append)`, for example. It's an excellent way to learn by doing, without relying solely on external manuals.

Beyond the interpreter, you have many quality resources: the official documentation at docs.python.org, courses on platforms like Microsoft Learn, Coursera, or Udacity , and interactive tutorials that let you program from your browser with an embedded interpreter. Google, for example, offers an introductory course based on internal material that covers Python 3 and goes from the fundamentals to more advanced topics.

If you prefer a video-free experience and want to learn at your own pace, there are online tutorials that combine theory and practical exercises in the same environment. Additionally, communities like Stack Overflow, specialized mailing lists, and learning forums can provide support when you get stuck on a specific detail while working in Windows.

This entire ecosystem means that, once you've completed the initial installation and configuration on Windows, continuing to grow as a Python programmer or data analyst is more a matter of perseverance than a lack of resources. For example, if your goal is to work with data, you can delve deeper into databases with specific guides.

After you familiarize yourself with the interpreter, .py scripts, argument handling, indentation, and functions, you'll find that learning Python on Windows ceases to be a technical obstacle course and becomes a fairly smooth process in which, with each small advance, you gain confidence and are encouraged to tackle more complex problems.

Python course from scratch
Related articles:
Python Course: Learn to Program from Scratch