标签:lse dia 执行 if语句 语句 else class 说明 范围
1.IF语句
if 1 == 1:
print(‘你答对了‘)
else:
print(‘你答错了‘)
if 1 == 1:
print(‘你答对了‘)
print(‘你答错了‘)
IF双层嵌套:
if 1 == 1:
if 2 == 2
print(‘你答对了‘)
else:
print(‘傻了吧‘)
else: print(‘你答错了‘)
IF跟input语法结合:
didian = input(‘请输入您的地点‘)
if didian == "幼儿园":
print(‘欢迎上车‘)
else:
print(‘滚‘)
ELIF(多条件判断)的运用:
didian = input(‘请输入您的地点:‘)
if didian == "幼儿园":
print(‘1号站台‘)
elif didian == "学校":
print(‘2号站台 ‘)
elif didian == ‘老家‘:
print(‘3号站台‘)
else:
print(‘不在我们的服务范围之内‘)
print(‘开始发车...‘)
PASS与IF的运用:
if 1 == 1:
pass
else:
print(‘sb‘)
注意:TAB键空四格说明下边的代码块属于上面从句,双等号==,条件后面记得加冒号:,注意PASS的用法(什么都不做,不执行)
2.基本数据类型
字符串(引号): name = ‘呵呵哒’
加法: n1 = "我" n2 = ‘是’ n3 = “SB” n4 = n1 + n2 +n3 = “我是SB”
乘法:n1 = "我" n2 = n1 * 10
数字:n1 = 10 n2 = 5 n3= n1 + n2 =15 (**双星号代表次方,%百分号代表取余数,//双杠取整除数(小数点前面的数)
标签:lse dia 执行 if语句 语句 else class 说明 范围
原文地址:https://www.cnblogs.com/newt/p/8963433.html