Unary Operators in Python
Python doesn’t support increment and decrement operators. Here are the implementation of Unary Operator in Python language:
a = 10
b = 5
# Unary plus (+)
c = -5
# The unary plus doesn't change the value of 'c'
print("Unary Plus:", +c)
# Unary minus (-)
# The unary minus negates the value of 'c'
print("Unary Minus:", -c)
# Unary logical NOT (!)
d = False
# Logical NOT of False is True
print("Unary Logical NOT:", not d)
# Unary bitwise NOT (~)
e = 1
# Bitwise NOT of 1 is -2
print("Unary Bitwise NOT:", ~e)
Output
Unary Plus: -5 Unary Minus: 5 Unary Logical NOT: True Unary Bitwise NOT: -2
Unary Operators in Programming
In programming, operators act as powerful tools for manipulating data and performing various operations. Among these, unary operators stand out, functioning on a single operand to transform or evaluate data in different ways. This post explains the types, implementations, and best practices associated with unary operators across several programming languages.
Table of Content
- What are Unary Operators?
- Types of Unary Operators
- Unary Operators in C
- Unary Operators in C++
- Unary Operators in Java
- Unary Operators in Python
- Unary Operators in C#
- Unary Operators in JavaScript
- Examples and Use Cases of Unary Operator
- Best Practices of Unary Operator
Contact Us