1.if Declaration
Single If by using a Boolean operator that declares and, or, and not.
If-elif-else. Elif that is else if
If expression1:
Expr1_true_suite
Elif expression2:
Expr2_true_suite
Else
None_of_the_above_suite
2.while statements
While expression:
Suite_to_repeat
The while statement has an optional ELSE clause. That
While expression:
Suite_to_repeat
Else
Expression
3.for statements
For Iter_var in iterable:
Suite_to_repeat
The For statement has an optional ELSE clause. That
For Iter_var in iterable:
Suite_to_repeat
Else
Expression
4.range () built-in functions
Range (start, end, step =1) The default step is 1
>>> Range (2, 19, 3)
[2, 5, 8, 11, 14, 17]
>>> Range (3, 7)
[3, 4, 5, 6]
Range () has two abbreviated syntax formats:
Range (end)
Range (start, end)
5.break and Continue,pass statements
The break statement can end the current loop and then jump to the next statement
Pass is an empty statement
6. Iterators and ITER () functions
>>> mytuple = (123, ' xyz ', 45.67)
>>> i = iter (mytuple)
>>> I.next ()
123
>>>
7. List resolution
[Expr for Iter_var in iterable]
List parsing also provides the syntax for an extended version number:
[Expr for Iter_var in iterable if COND_EXPR]
The core of this statement is the for loop, which iterates through all the entries of the Iterable object. The preceding expr is applied to each member of the sequence, and the final result value is the list produced by the expression. Iterative variables do not have to be part of an expression.
>>> [x * * 2 for X in range (6)]
[0, 1, 4, 9, 16, 25]
>>> seq = [11, 10, 9, 9, 10, 10, 9, 8, 23, 9, 7, 18, 12, 11, 12]
>>> [x for x in seq if x% 2]
[11, 9, 9, 9, 23, 9, 7, 11]
8
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Python six-core programming-conditions and loops