⚡0 XP🔥0

Installing Python & Running Code

Lesson 2 of 33 ⏱ 4 min read ✎ 1 exercises ❓ 5-question quiz ▶ Runs Python

Install Python on Windows, macOS or Linux, use IDLE and VS Code, and understand the difference between interactive mode and script mode.

Two ways to practise Python#

  1. In the browser (right here) - every lesson has a Try it Yourself editor. Perfect for learning.
  2. On your own computer - needed for real projects, files and libraries. This lesson shows you how.

Step 1: Download Python#

Go to python.org/downloads and download the latest Python 3 version (for example, 3.12 or 3.13).

Common Mistake

Always install Python 3. Python 2 is old and officially discontinued since 2020. Code from very old tutorials (like print "hello" without brackets) will not work in Python 3.

Step 2: Install#

On Windows#

  1. Run the downloaded .exe installer.
  2. Tick the box "Add python.exe to PATH" at the bottom of the first screen. This is very important.
  3. Click Install Now and wait for "Setup was successful".

On macOS#

Run the downloaded .pkg installer and follow the steps. On a Mac, the command is usually python3 instead of python.

On Linux (Ubuntu)#

Python 3 is usually pre-installed. If not:

sudo apt update
sudo apt install python3 python3-pip
हिंदी में समझें

Windows पर install करते समय "Add python.exe to PATH" वाला checkbox ज़रूर tick करें। अगर यह छूट गया, तो Command Prompt में python लिखने पर error आएगा: "python is not recognized..."। ऐसा हो जाए तो installer दोबारा चलाकर Modify चुनें और PATH वाला option tick कर दें।

Step 3: Verify the installation#

Open Command Prompt (Windows) or Terminal (macOS/Linux) and type:

python --version
Output
Python 3.12.4

If you see a version number, Python is ready. (On macOS/Linux use python3 --version.)

Interactive mode (the Python shell)#

Type python (or python3) and press Enter. You will see the >>> prompt:

>>> 5 + 3
8
>>> print("Hello")
Hello
>>> exit()

Every line runs immediately after you press Enter. This is called the REPL (Read-Eval-Print Loop). It is great for quick checks, like a calculator - but nothing is saved.

Script mode (saving your program)#

For real programs, write code in a file:

  1. Open any editor (Notepad works, but VS Code is better).
  2. Write your code and save it as hello.py.
  3. In the terminal, go to that folder and run:
python hello.py
# hello.py
print("Hello from a file!")
print("2 + 2 =", 2 + 2)
Output
Hello from a file!
2 + 2 = 4
▶ Try it YourselfPython
Ctrl + Enter to run

Choosing an editor (IDE)#

Editor Good for Notes
IDLE Absolute beginners Comes with Python. Search "IDLE" in the Start menu.
VS Code Students & professionals Free. Install the Python extension by Microsoft. Most popular choice.
PyCharm Community Bigger projects Free, powerful, a bit heavy for old laptops.
Jupyter Notebook Data science Run code in small cells with charts.
Google Colab No installation at all Runs in the browser, free GPU for AI work.
Tip

Recommended setup: Python 3 + VS Code + Python extension. In VS Code, open your .py file and click the ▶ (Run) button at the top-right.

Interactive vs Script mode#

Interactive mode (>>>) Script mode (.py file)
Runs one line at a time Runs the whole file
Shows results automatically You must use print() to see results
Code is lost when you close it Code is saved and reusable
Best for quick tests Best for real programs
Common Mistake

In interactive mode, typing 5 + 3 shows 8. But in a .py file, the line 5 + 3 shows nothing - you must write print(5 + 3).

Summary#

  • Download Python 3 from python.org; on Windows tick Add python.exe to PATH.
  • Check with python --version.
  • >>> = interactive mode (quick tests); .py files = script mode (real programs).
  • Use VS Code with the Python extension for daily work.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Check your setup

Print the following two lines exactly. (On your own computer, save this in a file setup.py and run python setup.py.)

Python is installed
Version 3
Expected output:
Python is installed
Version 3

Quick Quiz

Q1.

Which checkbox must you tick while installing Python on Windows?

Q2.

What is the file extension of a Python program?

Q3.

What does >>> mean in the terminal?

Q4.

Which command shows the installed Python version?

Q5.

Which is the best mode for writing a 50-line program you want to save and run again?