Python Install
Many PCs and Macs will have python already installed.If you are using Linux OS it has python also pre installed.
To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe):
To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type:
If you find that you do not have Python installed on your computer, then you can download it from the following website: https://www.python.org/ Downloading and installing python is free.
Save your file. Open your command line, navigate to the directory where you saved your file, and run:
The output should be:
C:\Users\Your Name>python --version
To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type:
python --version
If you find that you do not have Python installed on your computer, then you can download it from the following website: https://www.python.org/ Downloading and installing python is free.
Quickstart Python
Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed. Let's write our first Python file, called hello.py, which can be done in any text editor(like notepad, notepad++ etc):hello.py:
print("Hello, World!")
C:\Users\Your Name>python hello.py
The output should be:
Hello, World!
If you see the correct output. You have written and executed your first Python program.
Python Version
To check the Python version of the editor, you can find it by importing the sys module:
import sys
print(sys.version)
The Python Command Line
To test a short amount of code in python sometimes it is quickest and easiest not to write the code in a file. This is made possible because Python can be run as a command line itself. Type the following on the Windows, Mac or Linux command line:C:\Users\Your Name>python
if the "python" command did not work, you can try "py":
C:\Users\Your Name>py
From here you can write any python, including our hello world example from earlier in the 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!")
It will write "Hello, World!" in your 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!
If you want to exit from command line, you can simply type the following to quit the python command line interface:
exit()