1.set
Features: unordered and non-repeating collections
A. Create
Li = [] principle: List ((1,2,3,4)) list _init_ method, internal loop for loop (1,2,3,4)
Dictionary type definition: dict = {"K1": 123}
Set type definition: set = {"123", "456"}
B. function
Set ()
Create a Collection
LU = [1,2,1,2]
SS = Set (LU)
Print (ss)
Action Collection
Ss.add ()
Ss.clear ()
Ss.difference ()
2. Exercises:
What slots are added to remove updates
Old_dict = {
"#1": 8,
"#2": 4,
"#4": 2,
}
New_dict = {
"#1": 4,
"#2": 4,
"#3": 2,
}
3. Functions
function creation
Def f1 ():
Aaa
Bbb
Ccc
1.def keywords
Name of 2.F1 function
3. ()
4. Function body
function immediately terminates when executing the return function
Python default return value is None
function parameters
1. General parameters
2. The default parameter must be placed at the end of the parameter list
3. Specifying parameters
4.* receive dynamic Parameters by default will be passed in the parameters, placed in tuples
5.** Dictionary pass -through defaults to the passed-in parameters, placed in the dictionary
6. Universal parameter *args **kwargs
7. Supplementary reference global variable with uppercase read Assignment global change the value dictionary list of global variables within a function
4. Ternary operation
Basic structure: name = "Alex" if 1 = 1 Else "SB"
Lambda expression
Built-in functions
ABS Absolute
0,none, "", [], () A Boolean value of False
All ([1,2,3,4]) The all value within the all function is true all is True
Any ([1,2,3,4]) in any function as long as one is true, any is true
ASCII ()
Bin (5) decimal converted to 2 binary
Oct (9) decimal converted to 8 binary
Hex (9) decimal converted to 16 binary
Bytes string into bytes
s = "Chinese"
n = bytes (s,encoding= "Utf-8")
Print (n)
n = bytes (s,encoding= "GBK")
Print (n)
Bytes converted into strings
Str (bytes (s,encoding= "Utf-8"), encoding= "Utf-8")
5. File operation
1. Open File
f = open (' db ', ' R ') read-only
f = open (' db ', ' W ') write only
f = open (' db ', ' x ') file exists error does not exist create and write
f = open (' db ', ' a ') append
f = open (' db ', ' RB ') operation mode plus b such as WB, RB, XB represent bytes directly operation
2. Operating files
F.seek (1) byte method to locate the corresponding file location after overwriting
F.tell () gets the position of the current pointer
F.seek (F.tell ())
F.flush () Force write
For loop file Object f = open (XXX)
For line in F:
Print (line)
Python Learning Note Day3