Introduction to Python |
## Python past and present life
The founder of Python is Guido van Rossum. During the Christmas period of 1989, in order to kill time in Amsterdam, Guido van Rossum decided to develop a new script interpreter as a successor to the ABC language.Automated operation and maintenance, Automated testing, Big data analysis, crawlers, Web, etc.
Attention: The above highlighted font indicates that the company mainly uses Python language for developmentWhy Python instead of other languages?
C and Python, Java, C#, etc. C language: The code is compiled to obtain machine code. The machine code is directly executed on the processor, and each instruction controls the CPU workOther languages: The code is compiled to obtain bytecode, the virtual machine executes the bytecode and converts it into machine code and then executes it on the processorPython and C Python is a language developed from C For use: Python’s class library is complete and simple to use. If you want to achieve the same function, Python can solve it with 10 lines of code, while C may require 100 lines or more.
For speed: Python’s Compared with C, the running speed is definitely slower.
Regarding speed: Python
maybe slightly inferior in speed
Types of Python
Except for PyPy, the corresponding relationships and execution processes of other Pythons are as follows:
PyPy, in Based on Python, Python's bytecode is further processed to improve execution speed!
Getting started with Python
1. The first sentence of Python codeis in the /home/dev/ directory Create hello.py file with the following content:
print "hello,world"
|
##123 | #!/usr/bin/env python
print
"hello,world"
|
is enough. ps: You need to give hello.py execution permission before execution, chmod 755 hello.py
The python interpreter is loading .py file, the content will be encoded (default ascill)
ASCII (American Standard Code for Information Interchange, American Standard Information Interchange Code) is a computer coding system based on the Latin alphabet, mainly Used to display modern English and other Western European languages, it can only be represented by up to 8 bits (one byte), that is: 2**8 = 256, so the ASCII code can only represent up to 256 symbols.
Obviously ASCII code cannot represent all the various texts and symbols in the world, so a new one is needed that can represent The encoding of all characters and symbols, namely: Unicode
Unicode (Unicode, Universal Code, Unicode) is a character encoding used on computers. Unicode was created to solve the limitations of traditional character encoding schemes. It sets a unified and unique binary encoding for each character in each language, stipulating that all characters and symbols must be represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536,
Note: What is mentioned here is at least 2 bytes, possibly more
UTF-8, which is the compression of Unicode encoding And optimization, he no longer uses at least 2 bytes, but classifies all characters and symbols: the content in the ascii code is saved in 1 byte, European characters are saved in 2 bytes, and East Asian characters Use 3 bytes to save...
So, when the python interpreter loads the code in the .py file, it will encode the content (default ascill), if it is the following code:
Error: ascii code cannot represent Chinese
2 3 | #!/usr/bin/env python print"Hello, world"
|
34 !/usr/bin/env python | # -*- coding: utf-8 -*-
print
" Hello World"
4. Comments Current line attention: # Annotated content Multi-line comments: """ Annotated content """ 5. Execute the script and pass in parameters Python has a large number of modules, which makes developing Python programs very simple. The class library includes three types:
Python provides a sys module internally, in which sys.argv is used to capture the parameters passed in when executing python scripts
|
The above is the detailed content of What is Python? How to use Python?. For more information, please follow other related articles on the PHP Chinese website!