- 1

Boolean expressions and logical operators

Does negation operator exist in Python? For example, in C++, a token or literal can be negated using '!' before it, like so: x=1; cout<<!x; Output: 0

1st May 2020, 12:08 PM
Megha Suresh
5 Answers
- 2
No, I'm talking about the logical negation. Not the arithmetic negation. Take another look at my sample code.
1st May 2020, 12:12 PM
Megha Suresh
+ 5
Yes instead of ! not is used eg X=1 X= not 1 print(int(X)) This will result in 0
1st May 2020, 12:25 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Yes why not you may directly use negative symbol for that purpose. Eg X=1 X=-X Now X will be equal to -1
1st May 2020, 12:11 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Megha Suresh you should set the better answer mark on the answer wich has been the most helpful/informative... not to yours or one not relevant ^^
1st May 2020, 6:34 PM
visph
visph - avatar
- 1
Thank you very much. 😊
1st May 2020, 12:36 PM
Megha Suresh