Welcome to Module 2 of Python Fundamentals Level 1 Professional! In the previous module, you learned what programming is, what Python means, and how Python is used in the real world.
In this module, you will learn how to prepare your computer for Python programming, install Python, understand the tools used to write code, and create your first Python program.
By the end of this module, you should be able to:
Installing Python means adding the Python software to your computer so that you can write and run Python programs.
Think about installing WhatsApp on your phone. Before you can use the application, you must download and install it. Python works in a similar way. You need to install it before you can run Python programs directly on your computer.
Once Python is installed, your computer can understand and execute instructions written using the Python programming language.
You do not need an expensive computer to start learning Python. A normal computer that can run a supported operating system is usually enough for beginner programming.
You can also practise Python using online coding environments without installing it on your computer.
The safest place to download Python is its official website. Avoid downloading programming software from unknown websites.
Visit the official Python website: https://www.python.org/downloads/
Important: Download a currently supported Python release that is compatible with your operating system.
Many learners use Windows computers. Follow these steps to install Python on a Windows laptop or desktop.
Locate the Python installation file in your Downloads folder. Double-click the file to start the installation.
During installation, look for an option labelled: Add Python to PATH.
Select this option before continuing. It helps Windows find Python when you run Python commands from the command line.
Select the installation option, such as Install Now, and allow the installation process to finish.
When the installation is successful, close the installer. Python is now ready for you to test.
After installing Python, you should confirm that it works correctly. You can do this using the Windows Command Prompt.
python --version
If Python is installed and available through PATH, your computer should display the installed Python version.
For example:
Python 3.x.x
The exact version number depends on the version you installed. On some Windows computers, you may need to use:
py --version
If neither command works, check whether Python was installed correctly and whether the PATH option was selected.
A code editor is a software application that helps programmers write and edit computer instructions.
Think of a code editor as a digital notebook. Instead of writing stories or school notes, you use it to write programming code.
Visual Studio Code (VS Code) is a popular code editor used by programmers. It supports Python through extensions and provides features that make writing and managing code easier.
Official website: https://code.visualstudio.com/
IDLE is a basic development environment that comes with many standard Python installations. It allows beginners to write and run Python code.
PyCharm is a development environment designed for Python programming. It provides tools for writing, testing and managing larger Python projects.
Online Python editors allow you to write and run Python code through a web browser. They are useful when you cannot install Python on your computer.
Examples include:
The Python interactive shell is a place where you can type Python instructions and see the results immediately.
When you open the Python interactive shell, you may see three greater-than symbols:
>>
These symbols are called the Python prompt. They show that Python is ready to receive an instruction.
>>> print("Hello, World!")
Hello, World!
Python executes the instruction and displays the message. You can also use the interactive shell to perform calculations.
>>> 10 + 5
15
>>> 20 * 3
60
The interactive shell is useful for testing small pieces of code before adding them to a complete program.
It is time to write your first Python program! Programmers often begin with a simple program called Hello, World!
This program displays a welcome message on the computer screen.
Open IDLE, Visual Studio Code or another Python editor.
Create a new file where you can write your Python instructions.
print("Hello, World!")
Save the file with the name:
hello.py
The .py extension tells your computer that the file contains Python code.
Use the Run option in your editor or run the saved file from the command line.
For example, in Command Prompt, navigate to the folder containing the file and enter:
python hello.py
Your program should display:
Hello, World!
Congratulations! You have successfully created your first Python program.
The print() function is used to display information on the screen.
A function is a reusable instruction that performs a particular task. You will learn more about functions in a later module.
print("My name is Amina")
Output:
My name is Amina
print("I am a student")
Output:
I am a student
print(2026)
Output:
2026
Notice that text is normally placed inside quotation marks, while a number can be written without quotation marks.
A Python program can contain several instructions. Python normally executes them one after another, from top to bottom.
print("Welcome to CRMNuggets")
print("Learn Python Programming")
print("Practise every day")
print("Become a better programmer")
Output:
Welcome to CRMNuggets
Learn Python Programming
Practise every day
Become a better programmer
Each print() instruction displays a new line of information.
A comment is a note written inside a program to explain what a particular section of code does.
Python ignores comments when executing a program. Comments are useful because they help programmers understand their own code and explain it to other people.
# This program displays a welcome message
print("Welcome to Python")
Output:
Welcome to Python
The # symbol tells Python that the rest of that line is a comment.
Sometimes your Python program may not work as expected. This does not mean you are a bad programmer. Errors are a normal part of learning how to code.
Python instructions must be spelled correctly. For example, writing pritn() instead of print() will cause an error.
Text inside print() should normally be placed inside quotation marks.
Incorrect example:
print("Hello, World!)
Correct example:
print("Hello, World!")
Python uses parentheses in instructions such as print(). Forgetting a closing parenthesis can cause a syntax error.
Python program files should normally use the .py extension.
Correct filename:
myprogram.py
Imagine you are creating a small program for a student in a Nigerian secondary school. The program should display the student's introduction.
Write a Python program that displays:
print("My name is Tunde")
print("I am 13 years old")
print("I attend Bright Future School")
print("My favourite subject is Mathematics")
print("I am learning Python")
Expected output:
My name is Tunde
I am 13 years old
I attend Bright Future School
My favourite subject is Mathematics
I am learning Python
Change the information to your own details and run the program.
Imagine that your school wants a simple computer program to welcome new students.
print("BRIGHT FUTURE SECONDARY SCHOOL")
print("Welcome to our school!")
print("Education is the key to success")
print("Welcome to a new academic session")
You can replace the school name with the name of your own school.
| Term | Meaning |
|---|---|
| Installation | Adding software to a computer so it can be used. |
| Python Interpreter | A tool that executes Python instructions. |
| Code Editor | Software used to write and edit programming code. |
| IDLE | A basic development environment included with many Python installations. |
| Interactive Shell | A place where Python instructions can be entered and executed immediately. |
| print() | A Python function used to display information. |
| Comment | A note in code that Python ignores during execution. |
| .py | The common file extension used for Python programs. |
| Output | The result displayed after a program runs. |
In this module, you have learned that:
Answer the following questions to test your understanding.
Congratulations! You have completed Module 2 of Python Fundamentals Level 1 Professional.
In Module 3: Python Syntax, Comments and Indentation, you will learn the basic rules for writing Python code, how Python understands instructions, why spaces and indentation matter, and how to write clean and readable programs.
Keep practising. The more code you write, the more confident you will become!