any(): As long as one of the elements in the iterator object is true
all(): All the determinants in the iterator return true , The result is true
python What elements are false in ?
0、 An empty string 、None、False、 An empty list 、 An empty dictionary 、 An empty tuple 、 Empty set
data=[1,4,6,3,7,0]
print(any(data))
data1=[1,0,0,0]
print(any(data1))
data2=[0,0,0,0]
print(any(data2))
The printing results are as follows: :
True
True
False
data=[1,4,6,3,7,8]
print(all(data))
data1=[1,0,0,0]
print(all(data1))
data2=[0,0,0,0]
print(all(data2))
The printing results are as follows: :
True
False
False
IOError: I / O is abnormal
AttributeError: Trying to access an object that has no properties
ImportError: Unable to import modules and packages ,, It's basically a path problem
IndentationError:: Grammar mistakes , The code is not properly aligned
IndexError: Subscript index out of sequence boundary
KeyError: Trying to access a key that does not exist in the dictionary
SyntaxError: Code logic syntax error , Cannot perform
NameError: Use a variable that has not been assigned to an object
The same origin strategy needs to meet 3 Point requirements
The agreement is the same
Domain name is the same
The same port
for instance :
http://www.example.com/dir/page.html
Agreement is http://
Domain name is www.example.com
End ⼝ yes 80( The default end ⼝ It can be omitted )
Homologous policy ⽬ Of , It's to make sure that ⽤ Security of user information , prevent ⽌ Malicious ⽹ Station stealing data .
Pessimistic locking : Every time I go to get the data, I think others will modify it , So every time I get the data, I lock it , So that if people want to take this data, they will block Until it gets the lock . A lot of this locking mechanism is used in traditional relational databases , For example, line locks. 、 Table locks 、 Read the lock 、 Write locks, etc. , Lock before operation
Optimism lock : Every time I go to get the data, I think other people won't modify it , So it won't lock , But when updating, we will judge whether others have updated the data during this period , You can use the version number mechanism .
Back end :
1、 For buffer storage, the number of reads and writes is high 、 Less changing data , For example, the information on the home page of the website . When the application reads data , It is usually read from the buffer first , If it cannot be read or the data has become invalid , Then access the disk database , And write the data to the buffer again .
2、 Asynchronous way , If there is a time-consuming operation , Asynchronous ,celery
3、 Code optimization , Avoid too many cycles and judgments , If there are more than one if else Judge , Give priority to what is most likely to happen first .
Database optimization
1、 If there is any condition , Data can be stored redis, Fast reading speed
2、 Index 、 Foreign keys
front end :
1、html and css At the top of the page ,javascript At the bottom of the page , because javascript Loading ratio html and css Slow loading , So it's a priority to load html and css, In case of incomplete page display , Poor performance , Impact on user experience .
python The garbage collection mechanism is mainly based on reference counting , A mechanism supplemented by marker removal and generational clarity
When there is 1 When variables hold references to objects , The reference count of this object will be increased by 1;
When using del When deleting the object that the variable points to , If the reference count of the object is not 1, such as 3, At this point, the reference count will only be decremented 1, That is to say 2;
When called again del when , Turn into 1;
If you call 1 Time del, At this time, the object will be deleted .
class Animal(object):
def __init__(self,name):
self.name=name
def __del__(self):
print('{} The object was killed immediately '.format(self.name))
if __name__ == '__main__':
cat=Animal(' Persian cat ')
cat1=cat
cat2=cat
print(id(cat), id(cat1), id(cat2))
print(' Delete now cat object ')
del cat
print(' Delete now cat1 object ')
del cat1
print(' Delete now cat2 object ')
del cat2
Execution results :
1949389517488 1949389517488 1949389517488
Delete now cat object
Delete now cat1 object
Delete now cat2 object
The Persian cat object was killed immediately
A="abcdefg"
B="abfyt"
list=[]
for i in A:
for j in B:
if i==j:
list.append(i)
print(list)
res=''.join(list)
print(res)