Loading lesson…
Python is a modern high-level programming language created by Guido van Rossum in 1991. The name comes from the comedy show "Monty Python's Flying Circus," but the language itself is serious and powerful.
Why is Python so popular?
Where is Python used?
Step 1: Download Python
Step 2: Verify the installation
Open Command Prompt (Windows) or Terminal (Mac/Linux) and enter:
python --versionOr:
python3 --versionYou should see something like: Python 3.11.5
Step 3: Install a code editor
Recommended editors:
For beginners, we recommend VS Code.
A programming tradition is to start with a program that prints "Hello, World!". This is the simplest program that confirms everything works correctly.
Creating the file:
hello.pyprint("Hello, World!")Save the file
Running the program:
Option 1: From the command line
python hello.pyOption 2: In VS Code
Result:
You will see in the terminal:
Hello, World!Congratulations! You have written your first Python program!
Python has an interactive mode (REPL - Read-Eval-Print Loop) where you can run code immediately without creating files.
Starting interactive mode:
Open the command line and enter:
pythonOr:
python3You will see something like:
Python 3.11.5 (main, ...)
Type "help", "copyright", "credits" or "license" for more information.
>>>The >>> symbol is a prompt showing that Python is ready to accept commands.
Usage examples:
>>> print("Hello, Python!")
Hello, Python!
>>> 2 + 2
4
>>> print("This is my first Python code!")
This is my first Python code!Exiting interactive mode:
Enter:
>>> exit()Or press Ctrl+Z (Windows) or Ctrl+D (Mac/Linux)
When to use interactive mode:
When to use files:
Let's look at the basic structure of a Python program:
# This is a comment - Python ignores everything after the # symbol
# Importing modules (we will cover this in more detail later)
import math
# Comments explain the code
# This is just an example of program structure
# Running code
print("Hello! This is my first Python program")
# Simple output
print("Python is a great programming language!")Key points:
# - they help explain the codeCode style:
Python follows the philosophy that "beautiful code is readable code." It is important to:
Without this, Python will not be available from the command line, and you will not be able to run programs.
Python distinguishes between single (') and double (") quotes, but they must come in matching pairs.
File names with spaces or special characters can cause problems.
If the file is not saved, an older version of the code is run.
In this lesson we learned:
1. Python - a powerful and simple programming language
2. Installing Python - download from python.org and add it to PATH
3. First program - print("Hello, World!")
4. Interactive mode - quick code testing with python
5. Program structure - comments and code execution
You are now ready to write your first Python programs! Next lesson - variables and data types.