标准示例:
your_name = 'Jack Ma'示例:
ARVIN_AGE = 18例:
# The idle boy is almost invariably poor and anxious. 单行注释 ''' 这是多行注释示范 ''' """ 多行注释示范 """单if条件判断
if 条件: #条件判断 > < ==
print(‘真实’) #条件成立则执行
if 10 > 8: print("You are right.")if else条件判断
if 10 > 20: print("10 is bigger than 2.") else: print("10 is smaller than 2.")if elif elif else 条件判断
a = "jack" if 10 > 50: print("10 is bigger than 5.") elif type(a) == "str": print("a is a string.") elif 20 == 20: print("20 is equal 20.") else: print("All of them are false.") 运行结果: 20 is equal 20.多个同级if语句
a = "jack" if 10 == 20: print("10 is equal 20.") if a == "jack": print(a ,"is the same as jack.") if 10 == 10: print("10 is equal 10.") 运行结果: jack is the same as jack. 10 is equal 10.if与if语句之间的嵌套
id = int(input("input your id number: ")) pwd = input("input your passwrd: ") if id == 9: print("GO ON.") if pwd == "default": print("You logged in successfully.") else: print("Your password is incorrect.") else: print("Your id was typed incorrectly.")转载于:https://www.cnblogs.com/Tao9/p/10969101.html
相关资源:JAVA上百实例源码以及开源项目