Python3 Interpreter
On Linux/Unix systems, the default Python version is typically 2.x. We can install Python 3.x in the /usr/local/python3 directory.
After installation, we can add the path /usr/local/python3/bin to the environment variables of your Linux/Unix operating system. This allows you to start Python3 by entering the following command in the shell terminal:
$ PATH=$PATH:/usr/local/python3/bin/python3 # Set environment variable
$ python3 --version
Python 3.4.0
On Windows systems, you can set the Python environment variable with the following command, assuming Python is installed in C:\Python34:
set path=%path%;C:\python34
Interactive Programming
We can start the Python interpreter by entering the "Python" command in the command prompt:
$ python3
After executing the above command, the following window information appears:
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Enter the following statement in the Python prompt and press Enter to see the result:
print ("Hello, Python!");
The result of the above command is:
Hello, Python!
When typing a multi-line structure, line continuation is necessary. Consider the following if statement:
>>> flag = True
>>> if flag :
... print("flag condition is True!")
...
flag condition is True!
Scripted Programming
Copy the following code into the hello.py file:
print ("Hello, Python!");
Execute the script with the following command:
python3 hello.py
The output is:
Hello, Python!
On Linux/Unix systems, you can add the following command at the top of the script to make the Python script executable like a SHELL script:
#! /usr/bin/env python3
Then modify the script permissions to grant execution rights with the following command:
$ chmod +x hello.py
Execute the following command:
./hello.py
The output is:
Hello, Python!