Python Getting Started

Python Installation

Many PCs and Macs have Python installed.

To check if Python is installed on a Windows PC, look for Python in the start bar or run the following command on the command line (cmd.exe):

C:\Users\Your Name>python --version

To check if you have Python installed on Linux or Mac, open the command line on Linux or the terminal on Mac and type:

python --version

If you find that Python is not installed on your computer, you can download it for free from the following website:

https://www.python.org/

Python Quick Start

Python is an interpreted programming language, which means as a developer, you can write Python (.py) files in a text editor and then execute these files in the Python interpreter.

The way to run a Python file on the command line is as follows:

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

In which "helloworld.py" is the filename for Python.

Let's write our first Python file, named helloworld.py, which can be completed in any text editor.

helloworld.py

print("Hello, World!")

Run the instance

It's that simple. Save the file. Open the command line, navigate to the directory where the file is saved, and then run:

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

Output:

Hello, World!

Congratulations, you have written and executed your first Python program.

Python Command Line

To test a small amount of code in Python, writing code in a file is sometimes not the fastest or simplest method. It is possible to run Python as a command line.

Type the following content on the command line in Windows, Mac, or Linux:

C:\Users\Your Name>python

Here, you can write any python, including the hello world example at the beginning of this tutorial:

C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")

This will output "Hello, World!" in the command line:

C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Hello, World!

At any time, you can exit the python command-line interface by typing the following command:

exit()