已采納回答 / 粗實而夜雨
首先你得理解%的含義,這是取模(取余數)操作,1%2=2;用 num % 2 != 0作為條件也就是余數等于1,題目中要求的是取偶數位置的數據,而列表list的第一位是0,第二個位置是1,以此類推。
2021-01-10
最贊回答 / 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應該這樣對齊。
2021-01-06
最贊回答 / 粗實而夜雨
T = ((1+2),? ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))for i in T:? ? print(i)結果是這樣的:
3 (3,) ab (1,) (1,?2,?3,?4,?5)這里面包含了三個元組,但是最外面的大的(它本身)也算一個的吧,所以一共應該是4個元組
2021-01-05