Newbie: Object assignment return value 
Author Message
 Newbie: Object assignment return value

(I think) I'm trying to understand if object assignment has a return value.

Scenario A:

Quote:
>>> str( spam= 5 )
''
>>> str((spam=5))

  File "<stdin>", line 1
    str((spam=5))
            ^
SyntaxError: invalid syntax
Quote:
>>> #  continued : Scenario B:
>>> print spam

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'spam' is not defined

A: Why does including an extra set of paranthesis throw when the original doesn't?

B: What happend to my spam?
Espcially when this works:

Quote:
>>> str(int())
'0'
>>> str((int()))
'0'

Wishin'-I-had-something-practical-for-an-example,

Dean



Tue, 03 Aug 2004 02:51:40 GMT  
 Newbie: Object assignment return value

Quote:

> (I think) I'm trying to understand if object assignment has a
> return value.

Nope, it doesn't.  Assignment is a statement, not an expression,
in Python.

## Jason Orendorff    http://www.jorendorff.com/



Tue, 03 Aug 2004 06:27:45 GMT  
 Newbie: Object assignment return value

Quote:
>(I think) I'm trying to understand if object assignment has a return value.

>Scenario A:
>>>> str( spam= 5 )
>''
>>>> str((spam=5))
>  File "<stdin>", line 1
>    str((spam=5))
>            ^
>SyntaxError: invalid syntax
>>>> #  continued : Scenario B:
>>>> print spam
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>NameError: name 'spam' is not defined

>A: Why does including an extra set of paranthesis throw when the original doesn't?

>B: What happend to my spam?
>Espcially when this works:
>>>> str(int())
>'0'
>>>> str((int()))
>'0'

>Wishin'-I-had-something-practical-for-an-example,

>Dean

As others have pointed out, assignments are statements.  Expressions can
appear in statements but not vice versa.  Assignments do return values in
the sense that it can be used in chained assignments, but nothing else.

But you examples look strange anyway.  Did you copy and paste verbosely?
Which version of python are you using?  I get

Quote:
>>> str( spam= 5 )

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: this function takes no keyword arguments
Quote:
>>> str(int())

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: int requires at least 1 argument; 0 given
Quote:
>>> str((int()))

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: int requires at least 1 argument; 0 given

Huaiyu



Wed, 04 Aug 2004 03:24:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie on multiple return values

2. Return value of system call (newbie question)

3. (Newbie) F77 - function returns wrong value

4. Newbie Expect Question: where does Expect store values returned from an expect command

5. Newbie question about function return values

6. Value of an unknown object returned from odbc

7. Python COM Object Return Values in Delphi

8. id() returning different values for same object!

9. RETURN / RETURN-FROM and values

10. Newbie: Truth values (three-valued logic)

11. Object identity when returning an object with a function

12. Use of hex values for selected signal assignment

 

 
Powered by phpBB® Forum Software