最贊回答 / the_tops
template = '{0}, {1}'result = template.format('WorldLife is short', 'you need Python .')print(result)template = '{w}, {c}'World = 'WorldLife is short'you = 'you need Python .'result1 = template.format(w = World, c = you)print(result1)
2021-01-08
最贊回答 / 慕俠0184542
>>> L = [75, 92, 59, 68, 99]>>> sum = 0>>> for l in L:... ? ? sum = sum +l...?>>> print( sum / 5)78.6for和print應(yīng)該這樣對齊。
2021-01-06
最贊回答 / 粗實(shí)而夜雨
T = ((1+2),? ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))for i in T:? ? print(i)結(jié)果是這樣的:
3 (3,) ab (1,) (1,?2,?3,?4,?5)這里面包含了三個元組,但是最外面的大的(它本身)也算一個的吧,所以一共應(yīng)該是4個元組
2021-01-05
最贊回答 / 慕尼黑0535884
第一個應(yīng)該是錯誤的,但是被python解釋器處理了在'\\\,'這里第三個'\'應(yīng)該是轉(zhuǎn)譯的,但是后邊跟的是','無需轉(zhuǎn)譯,所以就把前邊的'\',直接輸出了吧如果第三個'\'后邊沒有任何字符(包括空格),就會直接報(bào)錯了
2021-01-04
最新回答 / 走出深坑_爬出井底
num=0L = ['Alice', 66, 'Bob', True, 'False', 100,33]for x in L:? ? num=num+1? ? if (isinstance(x,int)) and (not isinstance(x,bool)):? ? ? ? if x%2 == 0:? ? ? ? ? ? continue? ? ? ? print(x)isinstance(參數(shù)值,類型) 可以判斷參數(shù)值是否為指定的類型這里有個奇怪的地方是 isinstance(True,int) 的...
2021-01-03