If Else form
[Email protected] ~]$ VI testoperator.py#!/bin/python#operator testingnumber1=111number2=222if (NUMBER1>NUMBER2) : Print ("num1>num2") else:print ("Num2>num1") str1= "AAA" str2= "BBB" if (STR1==STR2): Print ("STR1=STR2") Else: Print ("Str1!=str2") a=3b=2if (a>b): Print ("A>b") elif (a==b): Print ("A=b") else:print ("A<b")
The judgment condition of the IF statement can be expressed by > (greater than), < (less than), = = (equals), >= (greater than or equal), <= (less than or equal).
If judgment condition: Execute statement ... else: Execute statement ....
When judging a condition for multiple values, you can use the following form:
If judgment Condition 1: Execute statement 1......elif judgment Condition 2: Execute statement 2......elif judgment Condition 3: Execute statement 3......else: Execute statement 4 ...
Since Python does not support switch statements, multiple conditions can only be determined by elif, and if the judgment requires multiple conditions to be judged at the same time, the or (or) is used to indicate that two conditions have a successful condition when they are established; When using and (and), Indicates that only two conditions have been established at the same time, the judgment condition succeeds.
Three forms of looping, shell support, Python supports only while and for in forms
While judging condition: Execute statement ...
For Iterating_var in Sequence:statements (s)
The three expression syntax for a For loop is as follows: for (EXP1; EXP2; EXP3)) do Command1 Command2 Command3 done
Python conditional statements and operators