Cycle
The representation of a For loop in the shell:
1, the number of paragraph form
For i in {1..10};d o echo $i;d one
2, detailed list (characters and the number of items not many)
For File in file1 file2 file3 file4 file5;do echo $File;d One
3, the existence of the file to cycle
For f in ' ls *.sh ';d o echo $f;d one
The representation of a For loop in Python:
There are two types of Python loops, one of which is the for...in loop, which sequentially iterates through each element in the list or tuple.
>>> names = ['Mic''Bob'jcy' ] for in names: ... Print name ... Micbobjcy
For Loop
Range (10) can generate a sequence of 0-10 integers, calculated as follows:
Sum = 0 for in range :+ = xprint sum
calculates the sum of 1-10 integers
The second loop is the while loop, which, as long as the condition is satisfied, loops continuously, exiting the loop when the condition is not satisfied.
For example, we want to calculate the sum of all the odd numbers within 100, which can be implemented with a while loop:
sum == while n > 0: = sum + n = n-2print sum
While Loop
The loop internal variable is n
continuously self-reducing until -1
it becomes, and the while condition is no longer satisfied, and the loop exits.
Conditional judgment
The Python program language specifies any non-0 and non-null (NULL) values of true,0 or NULL to FALSE.
In Python programming, if statements are used in the execution of control programs, in the basic form:
if < condition judgment 1>: < execute 1>elif < condition 2> :< execute 2>elif < condition judgment 3>: < execute 3>else: < Execute 4>
If Judgment
can also be abbreviated as:
if x: Print ' True ' as long as X is a non-0 value, a nonempty string, a non-empty list, and so on, it evaluates to true, otherwise false.
If judgment shorthand
The differences between Shell programming and Python programming