home PYTHONJAVA
 

Python3 interpreter

On Linux/Unix systems, the default python version is 2.x. We can install python3.x in the /usr/local/python3 directory.

After the installation is complete, we can add the path /usr/local/python3/bin to the environment variable of your Linux/Unix operating system so that you can enter the following via the shell terminal. Command to start Python3.

$ PATH=$PATH:/usr/local< Span class="pun">/python3/bin/python3 # Set environment variables
$ python3 --version
Python 3.4 .0

Under the Window system you can set the Python environment variable with the following command, assuming your Python is installed under C:\Python34:

set path=%< /span>path%;C:\python34

Interactive programming

We can start the Python interpreter by typing the "Python" command at the command prompt:

$ python3

After executing the above command, the following window message 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 at the python prompt and press Enter to see the effect:

print ("Hello, Python!");

The above command execution results are as follows:

Hello, Python!

Continuous line is required when typing a multi-line structure. We can look at the following if statement:

>>> flag = True
>>> if flag :
... print("flag Condition isTrue!")
...
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< /span>

The output is:

Hello, Python!

On Linux/Unix systems, you can add the following commands at the top of the script to make Python scripts executable like SHELL scripts:

#! /usr/bin/env python3

Then modify the script permissions to have execute permissions, the command is as follows:

$ chmod +x hello .py

Execute the following command:

./hello.< /span>py

The output is:

Hello, Python!






welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.