
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does ++ and -- operators work in Python?
In C, C++, Java etc ++ and -- operators increment and decrement value of a variable by 1. In Python these operators won't work.
In Python variables are just labels to objects in memory. In Python numeric objects are immutable. Hence by a++ (if a=10) we are trying to increment value of 10 object to 11 which is not allowed.
>>> a=10 >>> a++ SyntaxError: invalid syntax
Instead we have to use += operator
>>> a=a+1 >>> a 11
- Related Questions & Answers
- How does Overloading Operators work in Python?
- How does Python while loop work?
- How does mkdir -p work in Python?
- How does garbage collection work in Python?
- How does class inheritance work in Python?
- How does issubclass() function work in Python?
- How does isinstance() function work in Python?
- How does tuple comparison work in Python?
- How does Python dictionary keys() Method work?
- How does variable scopes work in Python Modules?
- How does [\d+] regular expression work in Python?
- How does \B regular expression work in Python?
- How does * operator work on list in Python?
- How does constructor method __init__ work in Python?
- How does jQuery.scrollTop() work?
Advertisements