While loop 1. Basic cycle
123456
while条件:# 循环体# 如果条件为真,那么循环体则执行# 如果条件为假,那么循环体不执行
2. BreakBreak to exit all loops
1234
whileTrue:print "123"breakprint"456"
3, continueContinue is used to exit the current loop and continue the next loop
1234
whileTrue:print "123"continueprint"456"
Exercises1. Use while loop input 1 2 3 4 5 6 8 9 102. For all numbers of 1-1003. All odd numbers in output 1-1004. All even
= [1,3,4,5] print([i for i in list1]) >>> [1,3,4,5]返回值:list#只是把原来的列表遍历了一遍,生成了和原列表一样的列表
稍作修改的列表推导式格式:[‘*‘+variable+‘*‘ for variable in list]例如:list1 = [‘a‘,‘b‘,‘c‘] print([‘*‘+i+‘*‘ for i in list1]) >>> [‘*a*‘, ‘*b*‘, ‘*c*‘]返回值:list#对variable进行修改,可以是int的操作,也可以是str的操作,具体需根据列表元素来执行
带有判断条件的列表推导式格式:[variable for variable in list if 条件表达式]例如:list1 = [2,3,4,2,1,2,23,54,21,33] print([i for i in list1 if i>20]) >>> [23, 54, 21, 33]返回值:list
多个列表推导式格式:[variable1+variable2 for varia
Basic knowledge of Python:Basic data type: int str list tuple dict boolThe attribute function of integral type1. Factory method converts a string into an integer type1 " 1234 " 2 b = int (a)3print(b)4print(type (b), b) # To view the type and return the value of B 5 # c = ' 124asd ' in seconds you contain a character, you cannot convert it with this method 6# You can see his type by print (type (c))Run results1 12342 class'int'> 12342, the use of bit_length1 num1, num2, num3, num4, NUM5 = 1,2,3
loop, add sequence numbers to sequences
5, Dictionary methodIncrease
SetDefault is not moving, no increase
By deleting
Pop button Delete
Popitem Delete the last
Clear Clear
Del Delete key or full divide
Change
Update merges another key-value team into one, the same overlay, without adding
Check
Get has a return value, no null is displayed
Ke
operation of this method when with starts running__exit__(self, exc_type, exc_val, exc_tb): The run of this method is triggered when the with run endsExc_type If an exception is thrown, this gets the type of the exceptionExc_val If an exception is thrown, the exception content is displayed hereEXC_TB If an exception is thrown, this shows whereUse or Benefits:1. The purpose of using the WITH statement is to put the code block in with, and with the end, the cleanup work is done automatically with
.
When a global variable has the same name as a local variable, the local variable functions within the function that defines the local variable, and in other places the global variable works.
ScopeProgram design concept, usually, the name used in a program code is not always valid/available, but the name of the availability of the generation? The scope of this name is the range of the code.Five. Nesting functionsFunctions are defined in the body of another function, called nested funct
appropriate URL, otherwise get the data is null value.2. The image has the function of anti-theft chain.Cause: The request header carried in the GET request for the picture has ' Referer ' or ' Host ', but the HTML page is automatically generated when the request is sent, which is the ' 127.0.0.1:5000/*** ' format.Solve the idea: in the background to simulate the good request header, add the relevant parameters in the headers to get the binary data of the picture, and then directly back to the
variable with the same name as the function and assign a value, do not overwrite. We can understand that a JavaScript code is a lexical analysis. When we execute a variable assignment in front of the function, the function object we get in the lexical analysis is overwritten by our variable assignment. Because our function is not executed at the time of execution, it is executed only when it is called.Script>Console.log (func); //f func (age) {var age;console.log (age), var = 23;console.log (ag
).
W, write-only mode. "unreadable; not exist; create; delete content;"
A, append mode. "Readable; not exist" create; "only append content;"
"+" means you can read and write a file at the same time
r+, can read and write files. "readable; writable; can be added"
w+, write and read
A +, with a
"U" means that the \ r \ n \ r \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r or r+ mode can be converted automatically when reading
RU
R+u
"B" means processing binary
Number
integer int
Plural complex
Floating point Float
Small integer Pool: -5~257boolean bool
True
Falsel
Ternary operations__author__="Kuankuan"if __name__=='__main__': A="'b='True'C='False' #method One: The result of the true if the condition is determined if the conditions else is falseD = bifAElseCPrint('method One output result:'+d)#method Two: Determine the condition and the result of the true or falseD = A andBorCPrint('method Two output results:
interfaces, it is no longer necessary to consider the details of the operating hardware and concentrate on developing their own applications. For example, the operating system provides the abstract concept of files, the operation of the file is the operation of the disk, with the file we do not have to consider the disk read and write control (such as the control of disk rotation, moving the head read and write data and other details), # Second: The application to the hardware resources of the
than the And,and priority or, that is, the priority relationship is () > Not > and > or, and the same priority is computed from left to right. (without a number of cases)x or Y, X is true, the value is x,x false, the value is Y, X and Y,x are true, the value is y,x false, and the value is x. (from left to right)Let's have a real battle. 1, 8 or 3 and 2 and 0 or 9 and 78 or 3--> X is straight out of 8, don't look at the back. 2, 0 or 2 and 3 and 4 or 6 and 0 or 30 or 2--and X is false, take th
box, the Representative has already entered it and we can verify it. the contents of the onchange domain are changed. scenario: Typically used for form elements, which are triggered when the element content is changed. (three-level linkage) onkeydown a keyboard key is pressed. Application Scenario: When the user presses the ENTER key in the last input box, the form submits. onkeypress a keyboard key is pressed and released. onkeyup a keyboard key is re
Adorner:Definition: The essence is a function, function: (Decorate other functions) is to add additional functions for other functions;Principle: 1, cannot modify the source code of the adornment function2. Cannot modify the calling mode of the decorated functionImplement the Adorner Knowledge Reserve:1, function is "variable"2. High-order function3. Nested functionsHigher order function + nested function = "Adorner"Import timedef Timer (func): def warper (*args,**kwargs): start_time =
implementation of the class with type" "type creates the Testmodelform class with arguments for the class name, the inheriting class, and the properties in the class""Meta= Type ('Meta', (object,), {'Model': Self.model_class,' Fields':'__all__'}) Testmodelform= Type ('Testmodelform', (Modelform,), {'Meta': meta})#equivalent toclassTestmodelform (modelform):classMeta:model=self.model_class Fields="__all__"4. Reverse Generate URL# examples are: namespace is a namespace, name is a URL aliasReverse
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.