If statement
VI 2.py
#! /usr/local/bin/python
Name = Raw_input ("Pls shuru name:")
PWD = raw_input ("Pls shuru pwd:")
If name = = "Hu" and pwd = = "123":
Print ("You is Right")
Else
Print ("pls retype")
: wq!
chmod +x 2.py
./2.py
-----------------
Summary: 3 cases of If statement:
If condition:
code block
Else
code block
2.
If condition:
code block
ELSF conditions:
code block
Else
code block
3. Conditions
True False
1>2 n1>n2 n1==n2
name = = "XXX" and pwd = = "XXX"
Name = = "XXXX" or pwd = = = "XXX"
Name! = "XXXX"
--------------------------------
While doing something or quitting until it's satisfied
While condition:
code block
VI 3.py
#! /usr/local/bin/python
Import time
N1 = True
While N1:
Print ("1")
Time.sleep (1)
N1 = False
Print ("End")
: wq!
chmod +x 3.py
[Email protected] hu]#./3.py
1
End
-------------------------------------
Import time
Kaishi = 1
Flag = True
While flag:
Print (Kaishi)
if Kaishi = = 10
Flag = False
Kaishi = Kaishi + 1
Time.sleep (3)
Print ("End")
-----------
Break jumps out of all loops in the while loop, the code below is not executing
Kaishi = 1
While True:
Print (Kaishi)
if Kaishi = = 10:
Break
Kaishi = Kaishi +1
Continue behind, performing the next loop
Jump out of this loop and continue to the next loop
While True:
Print ("123")
Break
----------
While True:
Print ("123")
Continue
Print ("123456")
Print numbers from 1 to 10 in addition to 7:
#! /usr/local/python
Start=1
While True:
If start ==7:
Start + = 1
Continue
Print (start)
If start = = 10:
Break
Start + = 1
10.py
#! /usr/local/bin/python
sum = 0
Start = 1
While start < 100:
temp = start% 2
if temp = = 1:
sum = sum + start
Else
sum = Sum-start
Start + = 1
Print (sum)
~
--------------
11.py
#! /usr/local/bin/python
I=0
While I < 3:
user_name = raw_input ("pls user_name:")
PWD = Raw_input ("pwd:")
if user_name = = "Hu" and pwd = = "123":
Print ("Yes")
Break
Else
Print ("No")
i + = 1
-------------
Coding:
Python 2.7
Unicode Utf-8 GBK
Middle is Unicode
Python
Direct Utf-8 and GBK direct conversion
zero3-conditional statements