num1 = 10
num2 = 0.5
result = num1 + num2
print(result) # ==> 10.5 num1 = 10
num2 = 0.5
result = num1 + num2
print(result) # ==> 10.5
num2 = 0.5
result = num1 + num2
print(result) # ==> 10.5 num1 = 10
num2 = 0.5
result = num1 + num2
print(result) # ==> 10.5
2023-05-01
如果一个字符串包含很多需要转义的字符,对每一个字符都进行转义会很麻烦。为了避免这种情况,我们可以在字符串前面加个前缀r,表示这是一个 raw 字符串,里面的字符就不需要转义了。
2023-04-27
# 需要注意的是,not计算的优先级是高于and和or的
# 所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
所以答案是 hello python ; hello world
# 所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
所以答案是 hello python ; hello world
2023-04-27
L = [95.5, 85, 59, 66, 72]
N = []
for item in L:
if(item > 60):
N.append(item)
N.sort(reverse=True)
print(N)
N = []
for item in L:
if(item > 60):
N.append(item)
N.sort(reverse=True)
print(N)
2023-04-24
template = 'life is short,{}'
print(template.format('you need Python'))
template = "life is {0},you need {1}"
print(template.format('short','Python'))
print(template.format('you need Python'))
template = "life is {0},you need {1}"
print(template.format('short','Python'))
2023-04-24