Duck dials to allow tuples, lists, or something that can be treated as one

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 

You will notice that foo() can function perfectly regardless of whether it passed spam as a list, as a tuple, or really as something that provides order for the element and can be addressed as a list.

How do you document this fact without telling the user to use a particular type?

+4
source share
1 answer

You speak,

 """spam is an object that supports indexing.""" 
+8
source

All Articles