Python: Getting Started

Everything you need to go from zero to writing and running your first Python program.

What is Python?

Python is a high-level, general-purpose programming language famous for its clean, almost English-like syntax. It was designed so that reading code feels natural, which means you spend less time deciphering symbols and more time actually building things. Under the hood Python is interpreted, meaning your code is executed line-by-line at runtime rather than compiled into machine code beforehand.

Think of Python as a Swiss army knife: it works equally well for a quick ten-line automation script and a million-line machine-learning framework. That versatility is exactly why it has become the world's most popular programming language.

Python at a Glance

Python combines readability, power, and a massive ecosystem into one language.

  • High-level: you deal with ideas, not memory addresses
  • Interpreted: run code instantly without a compile step
  • Dynamically typed: no need to declare variable types up front
  • Multi-paradigm: procedural, object-oriented, and functional styles all work
  • Open-source: free forever, backed by a vibrant community

Python Basics, First Taste

Python

A tiny program that shows off Python's readable style.

History of Python (Guido van Rossum)

In December 1989, a Dutch programmer named Guido van Rossum started working on a hobby project over the Christmas holidays. He wanted a language that sat between the low-level power of C and the friendly scripting style of the ABC language he had worked on previously. He named it Python, not after the snake, but after the BBC comedy series Monty Python's Flying Circus.

Python 1.0 shipped in 1994. Python 2.0 arrived in 2000, adding list comprehensions and garbage collection. Python 3.0 launched in 2008 with a deliberate break from backward compatibility to fix long-standing design mistakes. Python 2 reached end-of-life in 2020, and today everything new is written in Python 3.

Key Milestones

Python has steadily grown from a holiday hobby into the dominant language of data science and web development.

  • 1989, Guido starts writing Python as a side project
  • 1994, Python 1.0 released publicly
  • 2000, Python 2.0 with list comprehensions and GC
  • 2008, Python 3.0 (clean break, better unicode support)
  • 2020, Python 2 officially end-of-life
  • 2023+, Python 3.11 / 3.12 are significantly faster

Applications of Python

Python turns up everywhere, from NASA automation scripts to TikTok's recommendation engine. Below are the domains where Python genuinely shines.

Where Python Is Used

Python's wide standard library and rich third-party ecosystem make it a top choice across industries.

  • Web Development, Django, Flask, FastAPI power millions of backends
  • Data Science & Analytics, Pandas, NumPy, Matplotlib are industry standards
  • Machine Learning & AI, TensorFlow, PyTorch, scikit-learn run on Python
  • Automation & Scripting, file management, web scraping, task scheduling
  • Scientific Computing, used by researchers in biology, physics, and finance
  • DevOps & Cloud, Ansible, AWS Lambda functions, CI/CD pipelines
  • Game Development, Pygame, Ren'Py are popular Python game engines
  • Cybersecurity, penetration testing tools like Scapy are Python-based

Installing Python (Windows, macOS, Linux)

Before you can run any Python code locally, you need the Python interpreter on your machine. The official download is always at python.org/downloads. Always grab the latest stable Python 3 release.

Windows

Download the installer from python.org and run it. On the very first screen, tick the checkbox that says "Add Python to PATH", this is easy to miss and causes headaches later if skipped. Once installed, open Command Prompt and typepython --versionto confirm the install.

macOS

macOS ships with an older Python 2, so install Python 3 separately. The cleanest approach: install Homebrew first, then runbrew install python. Alternatively, download the macOS installer directly from python.org.

Linux

Most Linux distros already include Python 3. Update with your package manager:sudo apt install python3on Ubuntu/Debian orsudo dnf install python3on Fedora.

Quick Install Check

After installing, verify everything is working from your terminal.

  • Windows: open Command Prompt → type python --version
  • macOS / Linux: open Terminal → type python3 --version
  • You should see something like: Python 3.12.x

Installing VS Code for Python

Visual Studio Code is arguably the best free code editor for Python beginners. It is lightweight, opens instantly, and has an incredible Python extension that gives you auto-complete, error highlighting, and a built-in debugger in one package.

VS Code Setup Steps

Get VS Code ready for Python in under five minutes.

  • Download VS Code from code.visualstudio.com (free, cross-platform)
  • Open the Extensions panel (Ctrl+Shift+X) and search for "Python"
  • Install the official Microsoft Python extension
  • Open any .py file, VS Code will auto-detect your Python interpreter
  • Hit F5 to run and debug your script right inside the editor

Installing PyCharm IDE

PyCharm, made by JetBrains, is a fully dedicated Python IDE. It is heavier than VS Code but includes smarter code completion, a built-in virtual environment manager, and first-class support for Django and scientific computing. The Community Edition is completely free.

PyCharm vs VS Code

Both are excellent, choose based on what you value most.

  • PyCharm Community: free, Python-only, more Python-specific features
  • VS Code: free, lighter, works for any language, huge extension library
  • Beginners: VS Code is usually the easier starting point
  • Professionals: many Python developers eventually switch to PyCharm

Using Jupyter Notebook

Jupyter Notebook is different from a normal code editor, it runs in your browser and lets you mix live, executable code, formatted text (Markdown), and charts all in one document called a "notebook". Data scientists love it because you can experiment cell by cell without re-running the entire script every time.

Getting Jupyter Running

Install and launch Jupyter in three commands.

  • Install: pip install notebook
  • Launch: jupyter notebook (a browser tab opens automatically)
  • Create a new notebook: click New → Python 3
  • Each cell can contain code or Markdown text
  • Run a cell: Shift+Enter

Online Python Compilers

You do not always need a local install. Online compilers let you write and run Python straight in the browser, great for quick experiments, sharing code with friends, or learning on a machine where you can't install software.

Popular Online Options

All of these are free and require no signup to get started.

  • replit.com, full IDE in the browser, supports collaboration
  • python.org/shell, official minimal REPL, no frills
  • programiz.com/python-programming/online-compiler, beginner-friendly
  • google.com/colab, Jupyter notebook in the cloud (Google account needed)
  • DevoraCamp Compiler, the built-in compiler on this very page ↓

Hello World Program

Every programmer's first program is "Hello, World!", a tradition that dates back to Brian Kernighan's 1978 C book. In Python, it is just one line. That simplicity is not an accident; Guido van Rossum designed the language so that the straightforward thing is always the easy thing.

print() Function

print() sends output to the terminal (standard output). It is one of Python's built-in functions.

  • Built-in: no import needed, works straight away
  • Accepts multiple values separated by commas
  • Automatically adds a newline at the end by default
  • Tip: print("Hello") and print('Hello') both work, quotes are interchangeable

Hello, World!

Python

The classic first program, click Run to see it work.

Understanding the Python Interpreter

When you run a Python file, the Python interpreter reads your source code from top to bottom, line by line. It converts each line into bytecode, a simplified set of instructions, then executes that bytecode on the Python Virtual Machine (PVM). This all happens invisibly and instantly for small scripts.

Interpreter vs Compiler

Python is interpreted, which changes how you develop compared to languages like C or Java.

  • No build step: save the file, run it immediately
  • Errors appear at runtime for the line that fails, not at compile time
  • Slower raw speed than C/C++, but fast enough for most real-world tasks
  • CPython is the default interpreter (written in C), others exist like PyPy

Interpreter in Action

Python

Python runs each statement in order, see how an error stops execution partway through.

Running Python Scripts (.py files)

A Python script is just a plain text file saved with the .py extension. You run it from your terminal by passing the filename to the Python interpreter. This is the most common way to run Python code in production.

Running a Script

Three steps from file to output.

  • 1. Write your code in a file, e.g., hello.py
  • 2. Open Terminal / Command Prompt in the same folder
  • Windows: python hello.py
  • macOS / Linux: python3 hello.py
  • Tip: use cd to navigate to the folder first (cd Desktop)

A Typical Script File

Python

What the contents of hello.py might look like.

Python Interactive Shell (REPL)

The Python REPL (Read-Evaluate-Print Loop) is an interactive shell where you type one line of Python and instantly see the result. You don't save a file or press any run button, just type and hit Enter. It is fantastic for experimenting, testing a quick idea, or learning how a specific function behaves.

Start it by typing python (Windows) or python3 (macOS/Linux) in your terminal. You'll see a prompt like >>>, that means Python is waiting for your input. Type exit() to quit.

REPL Tips

Make the most of the interactive shell.

  • >>> is the primary prompt, type your code here
  • ... is the continuation prompt, for multi-line blocks like loops
  • Use the up arrow to recall previous commands
  • type(value) tells you the data type of any value
  • help(function) shows built-in documentation

REPL-Style One-Liners

Python

Short expressions you'd normally type directly into the interactive shell.

Python 2 vs Python 3

If you search for Python tutorials online you may run into Python 2 examples , old blog posts, university slides, legacy codebases. Python 2 and Python 3 look similar but have real differences that will cause errors if you mix them up. The short answer: always use Python 3 for anything new. Python 2 has been officially dead since January 2020.

Key Differences to Know

The most common Python 2 vs 3 differences you'll encounter.

  • print: Python 2 uses print "hello", Python 3 uses print("hello")
  • Division: in Python 2, 7/2 = 3 (integer); in Python 3, 7/2 = 3.5 (float)
  • input(): Python 2 had raw_input(); Python 3 uses just input()
  • Unicode: Python 3 strings are Unicode by default, no encoding headaches
  • range(): Python 2's range returned a list; Python 3's is a memory-efficient iterator

Python 3 Division Behaviour

Python

One of the most surprising Python 2 vs 3 differences.

PEP 8 Style Guide Basics

PEP stands for Python Enhancement Proposal, numbered documents that describe changes, improvements, or conventions for Python. PEP 8 specifically is the official style guide. Following it makes your code consistent with virtually all professional Python code in the world, which means other developers (and future you) will find it infinitely easier to read.

You don't need to memorise every rule on day one. Fix one habit at a time and it quickly becomes second nature.

Core PEP 8 Rules

The rules that appear in almost every code review.

  • Indentation: use 4 spaces per level, never tabs
  • Line length: keep lines under 79 characters
  • Blank lines: 2 blank lines between top-level functions/classes, 1 inside
  • Naming: variables and functions use snake_case (my_variable)
  • Naming: classes use PascalCase (MyClass)
  • Naming: constants use UPPER_SNAKE_CASE (MAX_RETRIES = 3)
  • Spaces: put spaces around operators (x = 1 + 2, not x=1+2)
  • Imports: one module per import line at the top of the file

PEP 8 Style in Practice

Python

Compare messy code vs clean PEP 8-compliant code.

Quiz, Test Your Knowledge

Let's see how much you picked up. Answer the questions below, no pressure, you can retry as many times as you like.

Knowledge Check

1. Who created the Python programming language?

2. Which of the following is the correct way to print "Hello, World!" in Python?

3. What file extension do Python script files use?

4. Which command starts the Python interactive shell (REPL)?

5. What does REPL stand for?

6. Which Python version is recommended for new projects today?

7. What does PEP stand for in PEP 8?

Next