"python"--initial knowledge of Python

Source: Internet
Author: User
Tags python script

python installation windows:
1. Download the installation package    https://www.python.org/downloads/2, install the    default installation path: C:\python273, configure environment variable    " Right-click Computer "-" "properties"-"advanced system settings"-"advanced"-"environment variable"-"in the second content box to find the variable named path of a row, double-click"- "python installation directory appended to the variable value, with;    such as: the original value; C:\python27, Remember that there's a semicolon in front
linux, Mac:
1 No installation required, original Python environment 2   3 ps: If you bring your own 2.6, update to 2.7

Update python:
1 windows:2 31, unloading load can be4       5 linux:6 7 Linux Yum relies on its own python, to prevent errors, the update here is actually to install a Python8         9 View the default Python versionTenpython-V one            a1, installing GCC for compiling python source code - Yum Install gcc -2, Download the source package, https://www.python.org/ftp/python/ the3, unzip and enter the source file -4, compiling and installing -./Configure -  make All + make Install -5, view version +/usr/local/bin/python2.7-V a6, modify the default Python version atmv/usr/bin/python/usr/bin/python2.6 -ln-s/usr/local/bin/python2.7/usr/bin/python -7, prevent Yum from executing exceptions, and modify the Python version used by Yum -vi/usr/bin/Yum -The head#!/usr/bin/python modified to #!/usr/bin/python2.6
View Code

Getting started with Python one, The first Python code:

Create the hello.py file under the/home/dev/directory, as Follows:

1 Print ("hello,world")

Execute the hello.py file, i.e.:python /home/dev/hello.py

The python internal execution process is as Follows:

second, the Interpreter:

When executing python/home/dev/hello.py in the previous step, it is clear that the hello.py script is executed by the Python interpreter.

If you want to execute a python script like executing a shell script, for example, you ./hello.py  would need to specify the interpreter at the head of the hello.py file, as Follows:

1 # !/usr/bin/env python 2   3 Print ("hello,world")

so, Execute:. /hello.py Can.

Ps: need to give hello.py Execute permission before execution, chmod 755 hello.py

third, the content code:The Python interpreter encodes the content when it loads the code in the. py file (default ascill)

ASCII (American Standard Code for information interchange, United States Standards Information Interchange Code) is a set of computer coding systems based on the Latin alphabet, mainly used to display modern English and other Western European languages, which can be used up to 8 Bit to represent (one byte), that is: 2**8 = 256, So the ASCII code can only represent a maximum of 256 symbols.

It is clear that the ASCII code cannot represent all the words and symbols in the world, so it is necessary to create a new encoding that can represent all the characters and symbols, namely: Unicode

Unicode (uniform code, Universal code, single Code) is a character encoding used on a computer. Unicode is created to address the limitations of the traditional character encoding scheme, which sets a uniform and unique binary encoding for each character in each language, which specifies that characters and symbols are represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536,
Note: here is a minimum of 2 bytes, possibly more

UTF-8, which is compression and optimization of Unicode encoding, does not use a minimum of 2 bytes, but instead classifies all characters and symbols: the contents of the ASCII code are saved with 1 bytes, the characters in Europe are saved in 2 bytes, and the characters in East Asia are saved in 3 bytes ...

therefore, when the Python interpreter loads the code in The. py file, The content is encoded (default Ascill)

Iv. notes:

When the line Stares: # is annotated content

Multiline comment: "" "annotated content" ""

v.. PYc file:

When you execute Python code, if you import a different. py file, A. PYc file with the same name is automatically generated during execution, which is the bytecode generated after the Python interpreter was Compiled.

Ps: code is compiled to generate bytecode, and bytecode can be obtained by decompile.

Vi. variables:

1. Declaring variables

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3   4 " Wupeiqi "

The code above declares a variable named: name, and the value of the variable name is: "wupeiqi"

The role of a variable: a nickname that refers to what is stored in an address in memory

Rules for variable definitions:

    • Variable names can only be any combination of letters, numbers, or underscores
    • The first character of a variable name cannot be a number
    • The following keywords cannot be declared as variable names
      [' and ', ' as ', ' assert ', ' break ', ' class ', ' Continue ', ' def ', ' del ', ' elif ', ' else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' Print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

2, the assignment of Variables:
1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 " Wupeiqi " 5 " Alex "

"python"--initial knowledge of Python

Related Article

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.