Python-start programming

Source: Internet
Author: User

Yesterday I ran Python on Windows, and today I learned Python on Linux.

Generally, Python has been installed on Linux. As long as we enter the command # python on the terminal, the interaction interface of Python is displayed, and The >>> prompt is displayed.

The Python version of my Linux system is 2.7. Although Python 3 and Python 2 are somewhat different, I should first learn the version of Python 2, and finally learn the difference with Python 3.

How to exit the Python interactive mode on Linux: >>> exit ()

 

I started writing the Python program!

Python program Extension:. py

Enter # vim 1.py in the Linux Command Line, enter the vim editor, and enter print "Hello world". Save and exit. We have written this Python program.

In this way, enter # python1.py in the command line and use the Python interpreter to explain the 1. py script.

Helloworld will appear on the screen.

In addition, we can use./1.py to execute it. Before that, we must add the Python path to the first line of 1. py:

#! /Usr/bin/python

And: add the executable permission to 1. py: chmod + x 1.py, so that we can execute it in./1. py.

 

 

Python file type:

Source code:

-The Python source code file uses the "py" extension, which is explained by the python program and does not need to be compiled;

 

Byte Code:

-Python source files with the extension "pyc" generated after compilation;

Compilation Method:

We need to write a Python program to compile 1.py.

Vim 2.py

Import py_compile

Py_compile.compile ("1. py ")

 

Input # python2.py on the Linux Command Line to generate a 1. pyc file (binary file)

# Python 1.pyc so that you can execute it.

 

 

Optimization code:

-Optimized source file with the extension ". pyo"

-Python-O-m py_compile 1.py

Generate a 1.pyo File

# Python 1.pyo execution

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.