专业编程基础技术教程

网站首页 > 基础教程 正文

Python基础-分支(if)(python基础架构)

ccvgpt 2024-07-20 11:50:40 基础教程 6 ℃
# 分支判断:if...else...
a = 2
b = 3
if a > b:
    print('a max!')
else:
    print("b max!")
# 判断相等和不相等:运算符(==、!=)
stu = 'wangwu'
if stu == 'wangwu':
    print("wangwu,You are on duty today.")
else:
    print("Please call wangwu to duty")

if stu !='zhangsan':
    print("Please call wangwu to duty")
else:
    print("you are on duty today.")
# 判断包含关系:in 和 not in
b = 'hello world'
if 'hello' in b:
    print('Contain')
else:
    print('Not Contain')
# 判断布尔类型
c = True
if c:
    print('c is True')
else:
    print('c is false')

# 多重判断
res = 72
if res >= 90:
    print('优秀')
elif res >= 70 :
    print('良好')
elif res >=60 :
    print('及格')
else:
    print('不及格')

Tags:

最近发表
标签列表