python flow control basics 05-

Control flow

1. Analyzing conditions

python code executed from top to bottom.

if conditions:

Indent 1 statement

elif Condition 2:

Indent statement 2

(... or write pass key. Do not write any code, prevent the error.)

...

else:

pass

Statement last

 

2. The three head operations

a = 7

print(True if a > 5 else False )

Another way print (True) if a> 5 else False

It can not be determined with the plurality of elif

3.while cycle and break

a = 0

= [2,3,5,6,8]

while a<5:

print (li [a])

a = a + 1

else:

print ( 'be added later while else') preceding conditions are not met, or the normal execution after execution.

Built-in function len (), the length of the calculated variables.

break terminates the loop.

4. iterative loop

= [2,3,5,6,8]

for i in li:

print(i)

print (parameter) print (i, end = ''), the default wrap.

for i in range(11):

print(i)

Range (11), to generate a default list of integers from 0 to 10, excluding 11.

range (0,11,2), can be added to step

for i in range(1,21):

if i % 5 == 0:

continue # skip this cycle, the next cycle performed

print(i)

else:

print ( 'is not forcibly interrupted') for loop can also be added else.

iterables for loop, the sequence type may tuples, strings, lists, sets, dictionaries can.

The value of circulating dictionary

di = { 'Name' 1234, 'it', 'SDS', 'receiver': 23}

for i in di.values():

5.linux command

cal view the calendar month

cal -y year view

cal 10 2010 relative to see October 2010

date to view the current time.

 

 

Guess you like

Origin www.cnblogs.com/winfun/p/10983791.html