2008-06-18
python 奇特的传参方法
When a final formal parameter of the form **name is present, it receives a dictionary containing all keyword arguments except for those corresponding to a formal parameter. This may be combined with a formal parameter of the form *name (described in the next subsection) which receives a tuple containing the positional arguments beyond the formal parameter list. (*name must occur before **name.) For example, if we define a function like this:
It could be called like this:
and of course it would print:
def cheeseshop(kind, *arguments, **keywords):
print "-- Do you have any", kind, '?'
print "-- I'm sorry, we're all out of", kind
for arg in arguments: print arg
print '-'*40
keys = keywords.keys()
keys.sort()
for kw in keys: print kw, ':', keywords[kw]
It could be called like this:
cheeseshop('Limburger', "It's very runny, sir.",
"It's really very, VERY runny, sir.",
client='John Cleese',
shopkeeper='Michael Palin',
sketch='Cheese Shop Sketch')
and of course it would print:
-- Do you have any Limburger ? -- I'm sorry, we're all out of Limburger It's very runny, sir. It's really very, VERY runny, sir. ---------------------------------------- client : John Cleese shopkeeper : Michael Palin sketch : Cheese Shop Sketch
发表评论
最新评论
-
使用ubuntu作为工作桌面详 ...
Oracle的Oracle SQLDeveloper可以用也可以把windowz ...
-- by zhoun -
使用ubuntu作为工作桌面详 ...
Ivan Li 写道moonjava 写道一些数据库的客户端呢? Oracle可 ...
-- by moonjava -
使用ubuntu作为工作桌面详 ...
moonjava 写道一些数据库的客户端呢? Oracle可以用Oracle S ...
-- by Ivan Li -
使用ubuntu作为工作桌面详 ...
写得不错!只是觉得linux下顺手的软件太少
-- by vdgame -
使用ubuntu作为工作桌面详 ...
一些数据库的客户端呢?
-- by moonjava







评论排行榜