Latest web development tutorials

Python3 interpreter

On Linux / Unix systems, general default python version 2.x, we can python3.x installed in / usr / local / python3 directory.

After installation is complete, we can add the path / usr / local / python3 / bin to your Linux / Unix operating system environment variables, so you can enter the following command to start a terminal shell Python3.

$ PATH=$PATH:/usr/local/python3/bin/python3    # 设置环境变量
$ python3 --version
Python 3.4.0

Under Window system you can be set by the following command Python environment variables, suppose your Python installation in the C: \ Python34:

set path=%path%;C:\python34

Interactive Programming

We can enter the "Python" command at a command prompt to start the Python interpreter:

$ python3

After executing the above command, the following message window:

$ 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 python prompt, and then press Enter to view operating results:

print ("Hello, Python!");

Results of the above command as follows:

Hello, Python!

When you type a multi-line structure, the continuation is necessary. We can look at the following if statement:

>>> flag = True
>>> if flag :
...     print("flag 条件为 True!")
flag 条件为 True!

Scripted Programming copy the following code to the file:

print ("Hello, Python!");

By the following command to execute the script:


The output is:

Hello, Python!

In Linux / Unix systems, you can add the following command at the top of the script to make Python scripts can be executed the same as SHELL script directly:

#! /usr/bin/env python3

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

$ chmod +x

Execute the following command:


The output is:

Hello, Python!