En Tue, 08 Apr 2008 01:57:47 -0300, Jason Scheirer
<[EMAIL PROTECTED]> escribió:
> You want to
> return s, t
> NOT return (s, t) -- this implicitly only returns ONE item
To avoid confusing the poor newbie: No, they're absolutely the same thing,
in both cases you're returning a tuple with two
En Tue, 08 Apr 2008 00:54:09 -0300, BonusOnus <[EMAIL PROTECTED]>
escribió:
> How do I pass a dictionary to a function as an argument?
The indentation is lost, so it's not easy to check your program.
> # Say I have a function foo...
Original: def foo(arg=[]). An empty list isn't a good defaul
Plus you probably don't want to set [] as default argument and then try to
access it like a dictionary; you'll get an exception if you ever call just
foo(), with no argument.
On Tue, Apr 8, 2008 at 12:57 AM, Jason Scheirer <[EMAIL PROTECTED]>
wrote:
> On Apr 7, 8:54 pm, BonusOnus <[EMAIL PROTECTE
On Apr 7, 8:54 pm, BonusOnus <[EMAIL PROTECTED]> wrote:
> How do I pass a dictionary to a function as an argument?
>
> # Say I have a function foo...
> def foo (arg=[]):
> x = arg['name']
> y = arg['len']
>
> s = len (x)
>
> t = s + y
>
> return (s, t)
>
> # The dictionary:
>
> dict = {}
> dict['na
On Apr 7, 10:54 pm, BonusOnus <[EMAIL PROTECTED]> wrote:
> How do I pass a dictionary to a function as an argument?
The same way you pass any other argument.
> # Say I have a function foo...
> def foo (arg=[]):
It's generally a bad idea to use [] as a default argument.
> x = arg['name']
> y = a
BonusOnus wrote:
> How do I pass a dictionary to a function as an argument?
>
>
> # Say I have a function foo...
> def foo (arg=[]):
> x = arg['name']
> y = arg['len']
>
> s = len (x)
>
> t = s + y
>
> return (s, t)
I assume you actually indented the body of the function?
> # The dictionary:
On 2008-04-07 08:54:09 PM, BonusOnus wrote:
> How do I pass a dictionary to a function as an argument?
>
>
> # Say I have a function foo...
> def foo (arg=[]):
Try:
def foo(arg={}):
Thanks,
Ricky
pgpXEZLwP4mLj.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-l
How do I pass a dictionary to a function as an argument?
# Say I have a function foo...
def foo (arg=[]):
x = arg['name']
y = arg['len']
s = len (x)
t = s + y
return (s, t)
# The dictionary:
dict = {}
dict['name'] = 'Joe Shmoe'
dict['len'] = 44
# I try to pass the dictionary as an argument