python logical operators

there are three logical operators in python.

if you have some experience about other programming languages, you might be familiar with ||, && and ! operation.

but python has logical operations like below

x and y
x or y
not x
I think it looks more readable.

and operation will return true if both x and y are true. otherwise false.
or operation will return true if either x or y is true. if both of them are false, it will return false. lastly, not operation will reverse x. if x is false, it will be true. otherwise false.

we can understand easier from example code.


x = True
y = False

print("x is true and y is false then : {}".format(x and y))

y = True
print("x is true and y is true then : {}".format(x and y))

print("x is true or y is true then : {}".format(x or y))

x = False
print("x is false or y is true then : {}".format(x or y))

print("x is false and then not x : {}".format(not x))

print("y is true and then not y : {}".format(not y))



Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2