Your First Programming Language
Python Introduction Setup
Giving the Computer Instructions
At its heart, programming is simply about writing a list of instructions for a computer to follow. Think of it like a recipe. A recipe lists steps in a specific order to achieve a goal, like baking a cake. A program lists steps for a computer to achieve a goal, like calculating a sum or displaying a message on the screen. The language we use to write these instructions is called a programming language.
There are many programming languages, but Python is a fantastic choice for beginners. Its syntax is clean and readable, often resembling plain English. This means you can focus more on the logic of what you're trying to build and less on memorising complex symbols and rules. Python was created in the late 1980s by , who wanted a language that was both powerful and easy to read. Its versatility is another major advantage; it's used for everything from web development and data science to artificial intelligence.
Getting Python on Your Machine
Before you can write any Python code, you need to install the Python interpreter on your computer. The interpreter is a program that reads your Python code and translates it into instructions that your computer's hardware can understand and execute. The installation process is straightforward and varies slightly depending on your operating system.
| Operating System | Installation Steps |
|---|---|
| Windows | Go to the official Python website, download the latest installer, and run it. Crucially, check the box that says "Add Python to PATH" during installation. |
| macOS | Python often comes pre-installed. Open the Terminal app and type python3 --version. If it's not installed or you need a newer version, download the installer from the official Python website. |
| Linux | Python is almost always pre-installed. Open a terminal and type python3 --version. If needed, you can install it using your distribution's package manager, such as sudo apt-get install python3 for Debian/Ubuntu. |
Once installed, you can verify it by opening your terminal (Command Prompt on Windows, Terminal on macOS/Linux) and typing python3 --version. You should see the version number you installed.
Your Programming Workspace
You can write Python code in any plain text editor, but most developers use an (IDE) or a specialised code editor. These tools make coding much easier with features like syntax highlighting, which colours your code to make it more readable, and code completion, which suggests code as you type.
For starting out, Python's built-in editor, called IDLE, is perfectly fine. It's installed automatically with Python. More powerful and popular free options include Visual Studio Code and PyCharm Community Edition. For now, any of these will work.
Hello, World!
It's a long-standing tradition in programming to make your first program in a new language simply display the text "Hello, World!" on the screen. It's a simple task that confirms your setup is working correctly. In Python, this is incredibly easy.
print("Hello, World!")
That's it. That's the entire program. The print() part is a function that tells Python to display whatever is inside the parentheses on the screen.
To run this, open your text editor or IDE, type that single line of code, and save the file as hello.py. The .py extension is important as it tells your computer that this is a Python file.
Next, open your terminal, navigate to the directory where you saved your file, and type the following command:
python3 hello.py
Note: On Windows, you might just need to type
python hello.pyinstead.
Press Enter, and you should see the words Hello, World! printed in the terminal. Congratulations, you've just written and run your first Python program.
At its core, programming is best described as:
Who is credited with creating the Python programming language?
With your environment set up and your first program running, you've taken the most important step. You're now ready to explore what Python can really do.
