
- 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
What is tilde (~) operator in Python?
The bitwise operator ~ (pronounced as tilde) is a complement operator. It takes one bit operand and returns its complement. If the operand is 1, it returns 0, and if it is 0, it returns 1
For example if a=60 (0011 1100 in binary) its complement is -61 (-0011 1101) stored in 2's complement
>>> a=60 >>> bin(a) '0b111100' >>> b=~a >>> a 60 >>> >>> b -61 >>> bin(b) '-0b111101
- Related Questions & Answers
- What is the use of tilde operator (~) in R?
- What is the "double tilde" (~~) operator in JavaScript?
- What is @ operator in Python?
- What is modulo % operator in Python?
- What is operator binding in Python?
- What is a dot operator in Python?
- What is function of ^ operator in Python
- What is "is not" operator in Python?
- What is Python equivalent of the ! operator?
- What is "not in" operator in Python?
- What does 'is' operator do in Python?
- What is right shift (>>) operator in Python?
- What is the purpose of the `//` operator in python?
- What is vertical bar in Python bitwise assignment operator?
- What is correct name of * operator available in Python?
Advertisements