[Tutor] dict vs several variables?

Peter Otten __peter__ at web.de
Fri Feb 17 14:52:31 CET 2012


leam hall wrote:

> My concern with variables is that they have to be passed in specific
> order to the function, 

Yes, unless you use keywords. You can invoke

def div(x, y):
   return x // y

a = div(3, 2)
b = div(y=3, x=2)
assert a == b

> and they may have to have their type set

I have no idea what you mean by "have their type set". Can you give an 
example?

> multiple times so that you can perform the right functions on them. In
> a dict you could set it on insert and not have to worry about it.

Instead you'll have to worry about the contents of the dict which I suspect 
will be even harder to verify in a non-trivial script.



More information about the Tutor mailing list