How to Install Python on Windows, Mac, and Linux
Many modern Windows PCs and macOS systems come with Python pre-installed. However, verifying the installation is essential before proceeding with development.
Checking Python Installation
On Windows:
To verify if Python is installed on a Windows computer, you can search for “Python” in the Start Menu or open the Command Prompt and run:
C:\Users\Your Name> python --version
On macOS and Linux:
For macOS or Linux users, open the Terminal (or Command Line) and type:
python --version
If Python is not found, you can freely download and install it from the official Python website:
Python Quickstart Tutorial
Python is an interpreted, high-level programming language. Developers typically write code in .py
files using a text editor and then execute them via the Python interpreter.
Creating Your First Python File
Let’s create a simple Python file named hello.py
:
print("Hello, World!")
Save the file. Then open your command line, navigate to the folder containing your file, and run:
C:\Users\Your Name> python hello.py
The expected output will be:
Hello, World!
Congratulations! You have just written and executed your very first Python program.
Running Python in the Command Line
For quick testing or debugging, Python can be used directly in the command line interface without creating a file.
Type the following in your terminal (Windows, macOS, or Linux):
python
If that does not work, try:
py
This will launch the interactive Python shell. From here, you can execute Python code line by line. For example:
>>> print("Hello, World!")
And the output will be:
Hello, World!
To exit the Python interactive shell, type:
exit()
Conclusion
Installing Python and running your first script is a simple yet essential step into the world of programming. With this guide by Devyra, you’ve now laid the foundation to build Python applications, automate tasks, and dive deeper into coding with confidence.