- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is behavior of ++ and -- operators in Python?
In C/C++ and Java etc, ++ and -- operators are defined as increment and decrement operators. In Python they are not defined as operators.
In Python objects are stored in memory. Variables are just the labels. Numeric objects are immutable. Hence they can't be incremented or decremented.
However, prefix ++ or -- doesn't give error but doesn't perform either.
>>> a=5 >>> b=6 >>> ++a 5 >>> --b 6
Postfix ++ or -- produce errors
>>> a=5 >>> b=6 >>> a++ SyntaxError: invalid syntax >>> b-- SyntaxError: invalid syntax
Advertisements