4
def foo(spam, obj_of_interest):
"""Pass a _____ and an object of interest, and return [something that does something worthwhile] """
    name = spam[0]
    quest = spam[1]
    fav_color = spam[2]
    # ... interesting code
    return obj_of_interest

您会注意到,foo()无论它是spam作为列表、元组还是真正作为对元素强制执行顺序并且可以像列表一样处理的任何东西,它都可以完美地运行。

您如何在不告诉用户使用特定类型的情况下记录这一事实?

4

1 回答 1

8

你说,

"""spam is an object that supports indexing."""
于 2013-02-06T13:35:18.433 回答