473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

auto-increment operator - why no syntax error?

I see python doesn't have ++ or -- operators unlike say, C.
I read some reasonings talking about immutable scalars and using ++/--
doesn't make much sense in python (not sure if ++i is that far-fetched
compared to the allowed i += 1)

In any case, I accidentally wrote ++n in python and it silently
accepted the expression and it took me a while to debug the problem.

Why are the following accepted even without a warning about syntax
error?
(I would expect the python grammar should catch these kind of syntax
errors)
>>n = 1
2 * +++++ n
2
>>n += 1
n
2
>>++n
2

Karthik
Dec 9 '07 #1
2 2360
On Dec 8, 7:58 pm, Karthik Gurusamy <kar1...@gmail.comwrote:
I see python doesn't have ++ or -- operators unlike say, C.
I read some reasonings talking about immutable scalars and using ++/--
doesn't make much sense in python (not sure if ++i is that far-fetched
compared to the allowed i += 1)

In any case, I accidentally wrote ++n in python and it silently
accepted the expression and it took me a while to debug the problem.

Why are the following accepted even without a warning about syntax
error?
(I would expect the python grammar should catch these kind of syntax
errors)
>n = 1
2 * +++++ n
2
>n += 1
n
2
>++n

2

Karthik
There is a unary operator "+". When you write ++n, it's evaluating +n,
and then +(that result).
Dec 9 '07 #2
On Sat, 08 Dec 2007 16:58:25 -0800, Karthik Gurusamy wrote:
Why are the following accepted even without a warning about syntax
error?
(I would expect the python grammar should catch these kind of syntax
errors)
>>>n = 1
2 * +++++ n
2
>>>n += 1
n
2
>>>++n
2
There is no syntax error. It is just some unary pluses "chained". Maybe
unexpected but no syntax error.

Ciao,
Marc 'BlackJack' Rintsch
Dec 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lew | last post by:
Hi all, I'm trying to create a page that has a user-selectable page auto-refresh option (IE 5.5). Essentially, it's a page that contains a checkbox, when the user checks the checkbox, I'd like...
1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
1
by: neridaj | last post by:
Hello, I've found a few postings of this problem but none of the answers seem to fix my problem. I have a content div wrapped around a left floated image and a right floated table. I want the...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.