Pre and Post Decrement Operator in Python
Here are the implementation of Pre and Post Decrement Operator in Python language:
num1 = 15
num2 = 20
postNum = num1 # Post Decrement
num1 -= 1
preNum = num2 - 1 # Pre Decrement
num2 -= 1
# Printing value of postNum after post decrement.
print("postNum =", postNum)
print("num1 =", num1)
# Printing value of preNum after pre decrement.
print("preNum =", preNum)
print("num2 =", num2)
Output
postNum = 15 num1 = 14 preNum = 19 num2 = 19
Pre and Post Decrement Operator in Programming
Pre-decrement and post-decrement are the two ways of using the decrement operator to decrement the value of a variable by 1. They can be used with numeric data type values such as int, float, double, etc. Pre-decrement and Post-decrement perform similar tasks with minor distinctions.
Table of Content
- What is a Pre-Decrement Operator?
- What is a Post-Decrement Operator?
- Pre and Post Decrement Operator in C
- Pre and Post Decrement Operator in C++
- Pre and Post Decrement Operator in Java
- Pre and Post Decrement Operator in Python
- Pre and Post Decrement Operator in C#
- Pre and Post Decrement Operator in Javascript
- Application of Pre and Post-Decrement Operators