【发布时间】:2011-11-16 21:38:07
【问题描述】:
我有一个返回列表或元组的方法。在参数中表示返回类型的最 Pythonic 方式是什么?
def names(self, section, as_type=()):
return type(as_type)(([m[0] for m in self.items(section)]))
【问题讨论】:
-
所以函数
names需要返回as_type参数中调用者所表示的一种或另一种类型?为什么调用者不能从names(事后)开始强制结果?
标签: python