下面是Zed的肖在學習Python提供了硬盤的方式代碼:這兩個功能是如何相同的?
ten_things = "Apples Oranges Crows Telephone Light Sugar"
print "Wait there's not 10 things in that list, let's fix that."
stuff = ten_things.split(' ')
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"]
while len(stuff) != 10:
next_one = more_stuff.pop()
print "Adding: ", next_one
stuff.append(next_one)
print "There's %d items now." % len(stuff)
print "There we go: ", stuff
print "Let's do some things with stuff."
print stuff[1]
print stuff[-1] # whoa! fancy
print stuff.pop()
print ' '.join(stuff) # what? cool!
print '#'.join(stuff[3:5]) # super stellar!
然後在研究演習之一,他說:
- 翻譯這兩種方式來查看函數調用。例如,
' '.join(things)
讀取 爲「加入things
它們之間‘ ‘
。」與此同時,join(' ', things)
手段,「呼叫join
與‘ ‘
和things
。」瞭解他們是如何真正的同樣的事情。
我的問題是,我很難看到它們是如何是相同的東西?根據我的理解,第一個函數是表示取things
中的任何內容,並將它們與' '
連接起來。但第二個功能(據我所知)是說叫join
,而用' '
和things
作爲一個參數?定義函數時你將使用它們的方式有多種?我很迷茫......你們能澄清一下嗎?
看一下'join'函數的規格。它對兩個論點有什麼影響? – Barmar
我想知道的主要是這個人發現一個內置'加入(delim,list)'函數的地方.... –
我懷疑你正在看一本書的舊版(不正確)版本,查看[同一章節在線](http://learnpythonthehardway.org/book/ex38.html)。不幸的是,我似乎無法在任何地方找到勘誤表。 –