Python if not Boolean | Example code

Using if not Boolean will do a negation of a boolean is the opposite of its current value. A boolean is a primitive data type and its value can be True or False only.

Simple If value is False, not value would be True, and the statement(s) in if-block will execute would be True.

Or If the value is True, not the value would be False, and the statement(s) in if-block will not execute.

Python if not Boolean Example

The statements inside if block execute only if the boolean value is False.

a = False

if not a:
	print('a is false.')

Output:

Python if not Boolean

Do comment if you have any doubts and suggestions on this Python boolean code.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.