如果一個字符串包含很多需要轉義的字符,對每一個字符都進行轉義會很麻煩。為了避免這種情況,我們可以在字符串前面加個前綴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