Advertisement



< Prev
Next >



Python - Logical Operators











The functioning of the not operator corresponds to the NOT gate. It inverts the value of a boolean expression. Let's see the syntax of the declaration of a not logical operator.

not <boolean-expression>


Rules of a not operator :





not Operator Example


# Python not logical operator example


a=10		#integer variable1
b=20 		#integer variable2
d=2.5 		#floating-point variable

str1 = 'a' 	#string variable
str2 ='b'  	#string variable



if not 10>15 :
    print("not(10>15) is true ")
		
		
if not(b<25 or b>19) :		#Invert of (b is less than 25 and a is greater than 19)
    print("not(b<25 or b>19), is false")


if not(str1=='a' and str2=='b'): #Inverting the boolean value of (str1=='a' and str2=='b')
    print("not(str1=='a' and str2=='b'), is false")


if d>2 and not(str2=='b') :	#Inverting the boolean value of an expression by, not(str2=='b')
    print("d>2  and not(str2=='b'), is true")


if not(a<=10 or d>=2.5)	:	#Inverting the boolean value of (a<=10 or d>=2.5)
    print("a<=10 or d<=2.5, is true")


if not a<10 :			#Inverting the boolean value of (a<10)
    print("not(a<10) is true")


if not 1 :			#Inverting boolean value true(1) to false(0)
    print("this won't be printed")


if not 0 :			#Inverting boolean value false(0) to true(1)
    print("not 0 is true")


Output -


!(10>15), is true
!(a<10) is true
not 0 is true




Please share this article -





< Prev
Next >
< Python relational operators
Python conditional operator >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement