- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Articles
- What is different in & and AND operators in Python?
- What is difference in Python operators != and "is not"?
- What is different in OR and AND operators in Python?
- What is different in | and OR operators in Python?
- What is the difference between = and == operators in Python?
- What is the difference between the != and operators in Python?
- What is correct operators precedence in Python?
- What is Practical Use of Reversed Set Operators in Python?
- What is Behavior Monitoring in Cybersecurity?
- What are boolean operators in Python?
- Increment and Decrement Operators in Python?
- What are different basic operators in Python?
- What are different arithmetic operators in Python?
- What is the difference between | and || operators in c#?
- What is the difference between >> and >>> operators in Java?

Advertisements