Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

surprised to "++" and "--"

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


weebinn at gmail

Sep 22, 2009, 8:47 PM

Post #1 of 4 (638 views)
Permalink
surprised to "++" and "--"

Hi,
I know that there is no "++" or "--" operator in python, but if "var++" or something like that in my code(you know, most of C/C++ coders may like this),there is nothing wrong reported and program goes on just like expected!!
This is obscure, maybe a bug.


rob.cliffe at btinternet

Sep 25, 2009, 3:37 AM

Post #2 of 4 (606 views)
Permalink
Re: surprised to "++" and "--" [In reply to]

I don't think this is quite true.

++var and --var
are legal albeit redundant expressions that equal var

var++ and var--
cause a SyntaxError, as they should.

Rob


----- Original Message -----
From: Wee Binn
To: python-dev [at] python
Sent: Wednesday, September 23, 2009 4:47 AM
Subject: [Python-Dev] surprised to "++" and "--"


Hi,
I know that there is no "++" or "--" operator in python, but if "var++" or something like that in my code(you know, most of C/C++ coders may like this),there is nothing wrong reported and program goes on just like expected!!
This is obscure, maybe a bug.


------------------------------------------------------------------------------


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/rob.cliffe%40btinternet.com


matthew at matthewwilkes

Sep 25, 2009, 3:58 AM

Post #3 of 4 (614 views)
Permalink
Re: surprised to "++" and "--" [In reply to]

> I know that there is no "++" or "--" operator in python, but if
> "var++" or something like that in my code(you know, most of C/C++
> coders may like this),there is nothing wrong reported and program
> goes on just like expected!!
> This is obscure, maybe a bug.

Hi,

Firstly, this list is for the development of Python, not with Python,
questions about problems you're having should generally go to the
users' list. Bug reports should go to the bug tracker at http://bugs.python.org/

However, in this particular case, there's no point submitting it; you
have made a mistake somewhere. As you say, there is no ++ or -- unary
postfix operator, but this DOES raise a SyntaxError:

> >>> var = 1
> >>> var++
> File "<stdin>", line 1
> var++
> ^
> SyntaxError: invalid syntax


The prefix form is valid, as + and - are both valid prefix unary
operators:

> >>> ++var
> 1
> >>> --var
> 1

Which are equivalent to:

> >>> +(+1)
> 1
> >>> -(-1)
> 1
>

If you were to try this with something that didn't implement __neg__
and __pos__, such as strings, you'd get:

> >>> ++var
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: bad operand type for unary +

Hope this clarifies things for you,

Matthew
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


facundobatista at gmail

Sep 25, 2009, 6:13 AM

Post #4 of 4 (614 views)
Permalink
Re: surprised to "++" and "--" [In reply to]

2009/9/23 Wee Binn <weebinn [at] gmail>:

>     I know that there is no "++" or "--" operator in python, but if "var++"
> or something like that in my code(you know, most of C/C++ coders may like
> this),there is nothing wrong reported and program goes on just like
> expected!!
>     This is obscure, maybe a bug.

You can not write "var++":

>>> var = 5
>>> var++
File "<ipython console>", line 1
var++
^
SyntaxError: invalid syntax
>>>

--
. Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.