one, loop (for, while)
A while loop is the execution of a loop body when a given condition is established (true), otherwise exiting the loop. A For loop is a repeated execution of a statement.
break terminates the For/while loop when needed
continue Skips the statement behind it, ends the loop, and starts the next round of loops.
1. For loop (for ... else ... )
Used to traverse an object and also has an optional else block that comes with it.
The format for the For statement is as follows:
For <> in < object collection;:
If < conditions;:
Break
If < conditions;:
Continue
< other statements >
Else
<>
Note: The value entered in the following example is coerced into a number with an int to be compared to a random number, which is the STR type before conversion.
2. While loop (while ... else ...) )
In Python, the while loop is used to loop the execution of a program, that is, under certain conditions, loop through a program. The basic form is as follows:
While judging condition:
EXECUTE statement
The executed statement can be a single statement or block of statements, and the execution can be any expression, and any value other than 0 or non-null is true. When the condition is false false, the loop ends.
Use while to implement the For loop above, as shown below,count needs to initialize the value, and each count will need +1, otherwise it will be 1, into the dead loop.
Ii. several ways of writing print
Here are a few ways to do print:
%s string
%d int
%.2f Float
Operators (arithmetic operators, comparison operators, logical operators)
Arithmetic operators:
+ Plus
-Minus
* Multiply
/except
Floating point Division (rounding)
% take-up
* * exponentiation
# count = count+1
# count+=1
# count = count-1
# count-=1
# count= Count*1
# count*=1
# count = Count/2
# count/=2
Comparison operators:
Python's standard comparison operator has:< <= > >= = = <> Returns the True/false boolean data type, depending on the true or false expression.
Logical operators:
And, or, not are the logical operators provided by Python, and the function is to concatenate the expressions together to get a Boolean value. For example, this is the following:
>>> 5 < 6 and 5 = = 6
False
>>>
>>> 8 > 6 or 5 < 6
True
>>>
>>> Not 4 <= 3
True
>>>
>>> 5 < 6 < # equals 5 < 6 and 6 <
True
Python Learning Notes (loops, several ways to print, operators)