Skip to main content

Example

Prompt
Print "Hello, World!" to the screen using the print() function.
Output: complete Python program

Python Install

To run Python on your own computer, start by checking whether it is there already, since Windows or Mac machines may come with it pre-installed.

On Linux or Mac, open the terminal and type python --version.

If you don't find it, the official website offers a free download: https://www.python.org/.

On Windows, search for Python or enter the command below in the Command Line:

Check Python version

main.py
C:\Users\Your Name>python --version

Python Quickstart

Python is an interpreted language: you write your code in .py files using a text editor, and the Python interpreter runs them.

To try it, use any text editor to create and save a file named hello.py. Next, open your command line, go to the directory that holds the file, and run it.

hello.py file

main.py
print("Hello, World!")

Run hello.py

main.py
C:\Users\Your Name>python hello.py

Python Version

Importing the sys module lets you find out which version of Python is running.

Example

See which Python version the editor uses:

Prompt
Import the sys module and print the Python version using sys.version.
Output: complete Python program

The Python Command Line

For a quick test of a few lines, you can skip the file, because Python can act as a command line of its own. On Windows, Mac, or Linux, type python (or py) at the command line and start writing Python code. Type exit() once you want to leave.

Start Python command line

main.py
C:\Users\Your Name>python

Hello World in command line

main.py
>>> print("Hello, World!")

Exit command line

main.py
exit()