Python Getting Started
Python Installation
Most modern PCs and Macs come with Python pre-installed. To verify if Python is already installed on your system, follow these steps:
On Windows:
Open the start menu.
Search for "Python."
In the Command Line (cmd.exe), run the following command:
On Linux or Mac:
Open the command line (Terminal for Mac).
Run the following command:
If you discover that Python is not installed on your computer, you can easily obtain it for free from the official website: Python.org.
Python Quickstart
Python is an interpreted programming language, which means that you create Python (.py) files using a text editor and then execute these files in the Python interpreter.
To run a Python file from the command line, use the following syntax:
In this example, "helloworld.py" is the name of your Python file.
Let's create our first Python file, named "helloworld.py." You can use any text editor to do this.
It's as simple as that. Save your file, open your command line, navigate to the directory where you saved the file, and execute the following command:
The output should display:
Congratulations, you've successfully written and executed your first Python program!
The Python Command Line
Sometimes, when testing a small piece of Python code, it's quicker and easier to run it directly from the command line. Python allows you to do this by opening an interactive Python session.
To start the Python command line, enter the following on the Windows, Mac, or Linux command line:
If the "python" command doesn't work, you can try "py" instead:
From the Python command line, you can run Python code interactively, as shown earlier with our "Hello, World!" example:
This will display "Hello, World!" in the command line.
To exit the Python command line interface when you're done, simply type:
With this knowledge, you're ready to embark on your Python programming journey. Happy coding!
Last updated