Python Fundamentals For Beginners
Introduction to Python
Setting Up Your Workspace
Before you can write code, you need a place to write it and a way for your computer to understand it. We'll use a program called Thonny, which is an Integrated Development Environment, or IDE. Think of an IDE as a special text editor built for programming. It helps you write code, find mistakes, and run your programs all in one place.
The great thing about Thonny is that it comes with Python already included, so you only need to install one thing.
To get started, go to the official Thonny website (thonny.org), download the installer for your operating system (Windows, Mac, or Linux), and run it. The setup process is straightforward; you can accept all the default settings.
Once Thonny is open, you'll see two main parts. The top part is the editor, where you'll write and save your programs. The bottom part is the Shell, which is a place to talk to Python directly. Let's start by writing a proper program in the editor.
Hello, World!
It's a long-standing tradition in programming to make your first program display the text "Hello, World!". This simple task confirms that everything is set up correctly.
In Python, we use a built-in command, or function, called print() to display output. Whatever you put inside the parentheses will be shown on the screen. Type the following line into the Thonny editor (the top panel):
print("Hello, World!")
Let's break this down. print is the name of the function. The parentheses () are used to give the function something to work with. The text "Hello, World!" is what we want to print. We put it in double quotes to tell Python that this is a piece of text, also known as a string.
Now, click the green "Run current script" button in the toolbar (it looks like a play symbol). Thonny will ask you to save the file first. Save it as hello.py. The .py extension is important because it tells the computer this is a Python file. Once saved, the program will run, and you'll see this in the Shell panel:
Hello, World!
That's it! You've just written and executed your first Python program.
The Interactive Prompt
The editor is for writing programs you want to save and run again. The Shell, also called the interactive prompt, is for trying out quick commands. You can type Python code directly into the Shell next to the >>> symbol and press Enter. Python will run that single line of code immediately.
Try it now. Click into the Shell panel and type:
>>> print("This is the interactive prompt.")
When you press Enter, Python executes the command instantly:
This is the interactive prompt.
The prompt is great for simple calculations, too. It's like a powerful calculator.
>>> 2 + 2
4
>>> 100 / 5
20.0
The interactive prompt gives you immediate feedback, making it a fantastic tool for experimenting and learning how different commands work without having to save a file each time.
What is the main advantage of using an Integrated Development Environment (IDE) like Thonny?
What is the primary purpose of the Shell (the bottom panel) in Thonny?
You've taken the first crucial steps into programming. You have a working setup and have successfully told the computer what to do.
