One, Python installation
Windows
1
、下载安装包
https:
/
/
www.python.org
/
downloads
/
2
、安装
默认安装路径:C:\python35
3
、配置环境变量
【右键计算机】
-
-
》【属性】
-
-
》【高级系统设置】
-
-
》【高级】
-
-
》【环境变量】
-
-
》【在第二个内容框中找到 变量名为Path 的一行,双击】
-
-
> 【Python安装目录追加到变值值中,用 ; 分割】
如:原来的值;C:\python35,切记前面有分号Second, variable \ character encoding
declaring variables
1 # _*_coding:utf-8_*_ 2 3 " Lidong "
The code above declares a variable named: Name, and the value of the variable name is: "Lidong"
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 ']
three, character 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-1, so the ASCII code can only represent a maximum of 255 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 ...
Notes
When the line stares: # is annotated content
Multiline Comment: "" "Annotated Content" ""
Iv. initial knowledge of data types
Some of the more important:
- Boolean: the keyword bool, with a value of true or false, logically true, false. Used for looping or judging
- Integer: the keyword int, such as 3,-1, also called an integral type.
- Floating point number: The keyword float, such as 3.2,7.92, is also called floating-point.
- String: The keyword str, such as "Hello python"; keyword Unicode, such as U "Hello".
- List: The keyword list is an ordered sequence of values, such as [3, 2, 5], and the value can be of any type.
- Tuple: A tuple of keywords, similar to a list, but with an immutable sequence of values, such as (1,3,5), (1,).
- Collection: The keyword set, which is a package filled with unordered values. Three major characteristics: disorder, certainty, and mutual specificity.
- Dictionary: Keyword dict, which is an unordered package of key-value pairs.
String formatted output
Method One:% placeholder
1 username = input ( " username: " ) 2 password = input ( " password: " ) 3 4 info = 5 username:%s 6 password:%s 7 "% ( Username, password) 8 9 print (Info)
PS: string is%s; integer%d; floating-point number%f
Method Two: Format
Username = input ("Username:"= input ("Password:" ) )print("username:{0}, password:{1}". Format (username, password))
String common functions: Hello = "My name is Lidong"
- Remove white space: print (hello. Strip())
- Split: Print (hello. Split())
- Length: Print (len (Hello))
- Index: Print (hello. Index("I"))
- Slices: print (hello[5:10])
V. Operators
1. Arithmetic Operation:
2. Comparison operation:
3. Assignment Operation:
4. Logical Operation:
5. Member Arithmetic:
Python Basics (i)