1 logical Operation And,or, not
(1) In the absence of () the not priority is higher than and,and priority higher than or, that is, the priority relationship is () >not>and>or, the same excellent
The first level is calculated from left to right.
(2) Calculate the results of the following example
13>4or4<3 and1==1#False21 < 2 and3 < 4or1>2#True32 > 1 and3 < 4or4 > 5 and2 < 1#True41 > 2 and3 < 4or4 > 5 and2 > 1or9 < 8#False51 > 1 and3 < 4or4 > 5 and2 > 1 and9 > 8or7 < 6#False6 not2 > 1 and3 < 4or4 > 5 and2 > 1 and9 > 8or7 < 6#False
Summary: x or Y, X is true, the value is X,x is False, the value is Y;x and Y, X is true, the value is Y,x is False, the value is x.
Or find the truth, and find a fake
2 Python base data type
(1) Str
~ ~ Slicing syntax: Str[start:end:step] Start: Start position, end: End position, step: Step
~ ~ Slicing rule: Gu Tou regardless of tail
~~str string Manipulation:
1 ret6 = S13.find ("Tory"# Find the location of ' Tory ' if not returned-12 Print(RET6)
3 Ret8 = S13.index ("Sylar") # Quest lead position. Attention. If the index is not found. Program will error
#Conditional JudgmentS14 ="123.16"S15="ABC"S16="[email protected]"#is it made up of letters and numbers ?Print(S14.isalnum ())Print(S15.isalnum ())Print(S16.isalnum ())#is it made up of letters?Print(S14.isalpha ())Print(S15.isalpha ())Print(S16.isalpha ())#Whether it consists of numbers, excluding decimal pointsPrint(S14.isdigit ())Print(S14.isdecimal ())Print(S14.isnumeric ())#This comparison of cattle B. Chinese is recognized.Print(S15.isdigit ())Print(S16.isdigit ())
(2) List
# iteration add LST = [ " Wang Zhiwen ", " Zhang Shan ", " The abyss of Misery " ]lst.extend ([ " Twist Vine ", " The twist doesn't hurt. ]) Print (LST) #[' Wang Zhiwen ', ' Zhang Shan ', ' The abyss of misery ', ' twist cane ', ' twist not pain ']
# Slice Modification
Lst[1:4:3] = [" Twist Vine "" wow "# edit also OK. If the step size is not 1, be careful. Number of elements print(LST)
#SortLST = [1, 11, 22, 2]lst.sort ()#sort. Default AscendingPrint(LST) lst.sort (reverse=true)#DescendingPrint(LST)#reversalLST = ["Taibai","too Dark","Colored","Silver King","Day Day","Taibai"]Print(LST) lst.reverse ()Print(LST) L= Len (LST)#the length of the listPrint(l)
Note that nested multi-level lists are reduced-dimension operations. One layer at a glance is good.
(3) Tuple tuples
Tuples: Commonly known as immutable lists. Also become read-only lists, tuples are also one of the basic data types of python, enclosed in parentheses, which can put any data type
the data, the query can be. Loops can also be. Slices can also. But just can't change. Regarding immutable, note: The immutable meaning of tuples here is that the child elements are immutable. and the child element
The inner child element can be changed, depending on whether the child element is a mutable object
" haha " " hehe " # tu[2] = ["Fdsaf"] # so change not tu[2].append (" Twist The vine "# it can be changed. No error Tu[2].append (" Wang Jianlin ")print(TU)
Note that if there is only one element in the tuple. Be sure to add a comma, otherwise it's not a tuple .
(4) Dictionary Dict
The keys in the dictionary must be dict immutable data , and the saved data is not saved in theorder that we added them. It is stored in the order of the hash table. And the hash table is not sequential. So the slicing work is not possible.
It can only get the data in Dict by key.
#Modification of the dictionaryDIC = {"ID": 123,"name":'Sylar'," Age": 18}dic1= {"ID": 456,"name":"Twist Rattan","OK":"wtf"}dic.update (DIC1)#Update the contents of the Dic1 to DIC. If the key has the same name. Modify the replacement. If no key exists, it is added.Print(DIC)Print(Dic1
# Use the items () to deconstruct Print # dict_items (' id ', ' 123 ', (' name ', ' Sylar '), (' Age ', ' + '), (' OK ', ' Kobe Bryant ')]) This thing is also a list. Only the list is loaded with a tuple. for inch # ?? This is deconstruction. Print (key, value) # deconstructed A, B = 1, 2print(A, B)
Nested dictionaries also use a reduced-dimension operation.
3 Small Data pools
Small Data Pool (Chang): Stores the values we have used in a small data pool. For other variables to use.
Small data pools are used for numbers and strings, and other data types do not exist.
For numbers: -5~256 is added to the small data pool. Each time the use of the same is an object.
For string strings:
1. If it is plain text information and underscores. Then this object will be added to the small data pool
2. If it is with a special character. Then it will not be added to the small data pool. Every time it's new.
3. If it is a single-letter *n case. ' A ' *20, within 20 units is possible. More than 20 units will not be added
into the small data pool
Note (in general): in the py file. If you are simply defining a string of characters. Then normally it would be
is added to the small data pool. We can think of this: Python will help us to cache strings when using strings.
, just point to the string the next time you make it. Can save a lot of memory.
Python Basic Knowledge collation