introduction of 1.1-python:
to put it simply, the python thing is a programming language called Guido van Rossum, a program ape who spent his time in 1989, determined to develop a script. Its previous name is an inheritance in the ABC language. It's called Python because this great programmer, Guido van Rossum, is a fan of the BBC TV series-Monty Python's Flying Circus (Monty Python's Flying Circus).
1.2 Why to learn Python: Learning Python first to understand what kind of language Python is, you have to learn from the classification of programming languages
C and Python, Java, C #, etc.
C Language: The code compiles the machine code, the machine code executes directly on the processor, each instruction controls the CPU to work
Other languages: Code compiles to get bytecode, virtual machines execute bytecode and convert to machine code and then execute on processor
The language of Python and C Python was developed by C.
For use with: Python's class library is complete and concise, if you want to implement the same functionality, Python 10 lines of code can be solved, C may require 100 lines or more.
For speed: Python runs faster than C, forcing it to slow down.
Python and Java, C #, etc.
For use with: Linux original Python, no other languages; The above languages have a very rich class library support
For speed: Python may be slightly slower in speed
So, there is no essential difference between Python and other languages, other differences are: good at a field, rich in talent, preconceived.
Types of 1.3-python
- Cpython
The official version of Python, implemented using the C language, is the most widely used, and the CPython implementation converts the source file (py file) into a bytecode file (PYc file) and then runs on the Python virtual machine.
- Jyhton
Python Java implementation, Jython will dynamically compile Python code into Java bytecode, and then run on the JVM.
- IronPython
In Python's C # implementation, IronPython compiles Python code into C # bytecode and then runs on the CLR. (similar to Jython)
- PyPy (Special)
Python implements Python, which compiles Python bytecode bytecode into machine code.
- Rubypython, Brython ...
In addition to PyPy, the corresponding relationship and execution flow of Python are as follows:
PyPy, the Python bytecode is further processed on the basis of Python, which improves execution speed!
2.1Python Environment
Install Python
Windows:
1234567 |
1
、下载安装包
https:
/
/
www.python.org
/
downloads
/
2
、安装
默认安装路径:C:\python27
3
、配置环境变量
【右键计算机】
-
-
》【属性】
-
-
》【高级系统设置】
-
-
》【高级】
-
-
》【环境变量】
-
-
》【在第二个内容框中找到 变量名为Path 的一行,双击】
-
-
> 【Python安装目录追加到变值值中,用 ; 分割】
如:原来的值;C:\python27,切记前面有分号
|
Linux:
123 |
无需安装,原装Python环境 ps:如果自带 2.6 ,请更新至 2.7 |
Update python
Windows:
Linux:
Linux Yum relies on its own python, to prevent errors, the update here is actually to install a python
12345678910111213141516171819 |
查看默认Python版本
python
-
V
1
、安装gcc,用于编译Python源码
yum install gcc
2
、下载源码包,https:
/
/
www.python.org
/
ftp
/
python
/
3
、解压并进入源码文件
4
、编译安装
.
/
configure
make
all
make install
5
、查看版本
/
usr
/
local
/
bin
/
python2.
7
-
V
6
、修改默认Python版本
mv
/
usr
/
bin
/
python
/
usr
/
bin
/
python2.
6
ln
-
s
/
usr
/
local
/
bin
/
python2.
7
/
usr
/
bin
/
python
7
、防止yum执行异常,修改yum使用的Python版本
vi
/
usr
/
bin
/
yum
将头部
#!/usr/bin/python 修改为 #!/usr/bin/python2.6
|
3.1-python Getting Started
|
First program "Hello world!" |
|
#!/usr/bin/env python #声明python的环境变量, here the difference between Env and no env is: Add env will be based on the environment variables configured by the system to use the default Python environment to explain the program, without Env is directly through/usr /bin/python to execute #-*-coding:utf-8-*- #声明字符编码print ("Hello World") #在屏幕上打印 ' Hello World ' |
3.2 python Chinese encoding
Before learning Python's Chinese encoding, we need to know what the code is:
- Coding is the use of predetermined methods to digitally encode text, numbers, or other objects, or to convert information into a prescribed electrical pulse signal. Coding is the process of converting information from one form or format to another.
- However we need to understand the character encoding as follows:
- ASCII code: United States Standard Information Interchange code, mainly used to display English and European languages; it can only be represented by a maximum of 8 bits (one byte), that is: 2**8 = 256, so the ASCII code can represent up to 256 symbols.
- Unicode code: Also known as the Universal Code, the purpose is to solve 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 although some characters and symbols are represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536.
- Utf-8: Is the compression and optimization of Unicode encoding, he no longer uses a minimum of 2 bytes, but all the characters and symbols are categorized: the contents of the ASCII code is saved with 1 bytes, the European characters are saved with 2 bytes, the Chinese character is saved in 3 bytes.
There is a difference between the Chinese encoding between python2.x and 3.x: it is necessary to declare or specify character encoding in the python2.x series environment, however python3.x does not need to declare character encoding.
- The Chinese code is as follows:
- GB2312: GB code, was born in 1980, contains more than 7,000 Chinese characters
- gbk:1995 year, a total of more than 20,000 Chinese characters included
- GB18030: Is the 2000 to replace GBK1.0 and the birth of the official national standards, but also included the language of minority languages
Introduction and foundation of automation-python