content Encoding
- 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 ...
Comments
When the line stares: # is annotated content
- Multiline Comment: "" "Annotated Content" ""
Execute script incoming parameters
Python has a large number of modules, which makes developing Python programs very concise. The class library includes three:
-
- Python-supplied modules
- Industry-Open Source modules
- Modules developed by programmers themselves
Python internally provides a SYS module where SYS.ARGV is used to capture parameters passed in when executing a python script
# !/usr/bin/env python # -*-coding:utf-8-*- "Wupeiqi"
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.
Variable
- declaring variables
1 # !/usr/bin/env python 2 3 # -*-coding:utf-8-*- 4 5 " Wupeiqi "
The code above declares a variable named: Name, and the value of the variable name is: "Wupeiqi"
2. 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 ', ' fi Nally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' t Ry ', ' while ', ' with ', ' yield ']
3. Assigning values to variables
1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 " Wupeiqi " 5 " Alex "
1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 " Wupeiqi " 5 name2 = name1
Input
1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 # assigning user-entered content to the name variable 5 name = Raw_input (" Please enter user name:")6 7 # Print the input content 8 Print Name
When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely:
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 ImportGetpass5 6 #assigning user-entered content to the name variable7PWD = Getpass.getpass ("Please enter your password:")8 9 #Print What you have enteredTen PrintPwd
Little Ha Co python lesson three-character set encoding