1. Is and = = usage and difference: = = is a comparison operator in the Python standard operator, which is used to compare the value of two objects for equality
' Cheesezh ' ' Cheesezh '>>> a = = btrue
Is the same memory address that compares two variable values
>>> x = y = [4,5,6]>>> z = [4,5,6]>>> x = = ytrue>>> x ==
Ztrue
is
ytrue
is
zfalse
2. String stitching method Note that the concatenation of strings can only be a string of both sides, cannot be spliced with numbers or other types on the efficiency of format >% > + 1, plus ' + ', multiplication sign ' * '
' Fiona ' ' A '>>> name + age 'Fiona22'>>> name*5' Fionafionafionafionafiona'
2,% s
' Fiona ' ' Your name is%s '% name'your name is Fiona'
There are also%d (decimal) and%f (the default is 6 digits after the decimal point,%.3f means that 3 decimal places are reserved), can only pass in integers and floating-point numbers, and%s is a string and a number that can be passed
3. Format
' Fiona ' ' {} is a good girl ' . Format (name) ' Fiona is a good girl '
% and format belong to formatted output (https://www.cnblogs.com/fat39/p/7159881.html)
3.and,not. Priority of OR
not and or and or and 5andor and 77
And: When two conditions are set, the output is true, otherwise false, to the two conditions are compared, will enter the last or: when the two conditions of one of the time, the output is true, otherwise false, if the first condition is set, then the following not is compared: is the input worth 4. Depth copy1. Shallow copy () is different from the assignment, the memory address changes, generating a new memory address
# shallow copy lists, dictionaries are the same. Take the list for example. L1 = [1,2,3,4# ID memory address is not the same, created two space l1.append ('Barry'# One change, copy does not change print# [1, 2, 3, 4, ' Barry '] 41709256print # [1, 2, 3, 4] 41708616
2. Nesting # The first layer is independent. Starting from the second tier is common, and changing one will change. # There are nested layers and the list will be added. The overall memory address is inconsistent. Nested memory addresses are the same.
L1 = [1,[22,33,44],3,4= l1.copy () l1[1].append ('+') Print#[1, [+], 3, 4] 35417160 35417800print#[1, [22, 33, 4 4, ' 35417864 ', 3, 4] 35417800
3. Deep copy.deepcopy () # for deep copy, the two are completely independent, changing any element (no matter how many layers), and the other will never change. Copying a copy, completely unchanged, will not be affected by L1. L1 change, L2 will not follow change. Copy Code
#Deep copy.deepcopy ()ImportCopy#introduce modules firstL1 = [1,[22,33,44],3,4,]l2=copy.deepcopy (L1)#Change the first layerL1[0] = 111Print(L1)#[111, [+], 3, 4]Print(L2)#[1, [+], 3, 4]#Change the second tierL1[1].append ('Barry')Print(L1)#[111, [+], [+], ' Barry '], 3, 4]Print(L2)#[1, [+], 3, 4]
python--some basic knowledge