例如,這裏有一個函數,它接受5個參數,並反轉順序如何在不定義列表長度的情況下將列表作爲參數輸入?
def reverseList(a,b,c,d,e):
normalList = [a,b,c,d,e]
reverseList = reversed(normalList)
printedList = []
for eachit in reverseList:
printedList.append(eachit)
print "This is the list that was entered: %r" % (normalList)
print "This is the same list, but in reverse: %r" % (printedList)
我是新來的這一點,所以我無法弄清楚如何進入「自定義」列表中,例如不限制可以在該功能中輸入多少個數字。
你可以使用'* args',但在這種情況下,我建議只是傳入一個列表... – mgilson