“ Comparison operator ” Compare two values , Evaluate to a Boolean value .
if Statement by if、elif、else form .
if "a" == "b":
print("a == b")
elif 2 != 2:
print("2!=2")
elif 2 < 1:
print("2 < 1")
elif 2 > 3:
print("2 > 3")
elif 2 <= 1:
print("2 <= 1")
elif 2 >= 3:
print("2 >= 3")
elif True and False:
print("True and False")
elif False or False:
print("False or False")
elif not True:
print("not True")
else:
print("nothing is right")
while True:
print("Your are right")
for i in range(10):
if i == 2:
continue
if i == 5:
break;
print(i)
import random
i = random.randint(1, 10)
print(i)
from random import *
i = randint(1, 10)
print(i)
def Method name ( Parameters ):
Method body
return Return value
Arguments and variables assigned in the called function , At the end of the function “ Local scope ”.
Variables assigned outside all functions , Belong to “ Global scope ”. Variables in local scope , go by the name of “ local variable ”.
Variables in global scope , go by the name of “ Global variables ”.
If you need to modify global variables within a function , Just use global sentence .
Yes 4 Rules , To distinguish whether a variable is in local scope or global scope :
1. If the variable is used in the global scope ( That is, outside of all functions ), It is always a global variable .
2. If in a function , There are... For this variable global sentence , It's a global variable .
3. otherwise , If the variable is used for an assignment statement in a function , It's a local variable .
4. however , If the variable is not used in the assignment statement , It's a global variable .
try:
Code block
except Error code :
Code block
finally:
Code block