- if基本语句
- if name == feta:
print("测试大王")
else:
print("测试小弟")
- if嵌套
- if name == feta:
if company=shuoye:
print(“海豹电竞”)
else:
print("华为")
else:
print("高级会员")
- if elif
- if 条件1:
pass
elif 条件2:
pass
elif 条件3:
pass
else:
passprint(‘end‘)
- if 条件1:
- 字符串 - n1 = "alex" n2 = ‘root‘ n3 = """eric""" n4=‘‘‘tony‘‘‘
数字 - age=21 weight = 64 fight = 5加减乘除等:
字符串:
加法:
n1 = "alex"
n2 = "sb"
n4 = "db"
n3 = n1 + n2 + n4
# "alexsbdb"乘法:
n1 = "alex"
n3 = n1 * 10
数字:
n1 = 9
n2 = 2n3 = n1 + n2
n3 = n1 - n2
n3 = n1 * n2
n3 = n1 / n2
n3 = n1 % n2 (取余)
n3 = n1 ** n2 (乘方)
n3 = n1 // n2 (取商)
出题:
11 12 13 ...num = 12
n = num % 2
if n == 0:
print(‘偶数‘)
else:
print(‘奇数‘) - tips: 缩进用4个空格,快捷键是tab键
原文地址:https://www.cnblogs.com/feta/p/9886665.html
时间: 2024-11-08 21:05:07