标准示例:
your_name = 'Jack Ma'
示例:
ARVIN_AGE = 18
例:
# The idle boy is almost invariably poor and anxious. 单行注释
'''
这是多行注释示范
'''
"""
多行注释示范
"""
your_id = input("input your id identifier: ")
your_pwd = input("input your password: ")
print("Your id is {}, Your password is {}".format(your_id, your_pwd))
运行结果:
input your id identifier: Jack
input your password: default
Your id is Jack, Your password is default
单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 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.")
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有