Peng  Zup
0
Q:

logical operator in python

# Python Operators
Operator	Name			Example
+			Addition		x + y	
-			Subtraction		x - y	
*			Multiplication	x * y	
/			Division		x / y	
%			Modulus			x % y	
**			Exponentiation	x ** y	
//			Floor division	x // y
17
# Syntax for Boolean expression with or in Python
exp1 or exp2
6
x = 10
y = 12

# Output: x > y is False
print('x > y is',x>y)

# Output: x < y is True
print('x < y is',x<y)

# Output: x == y is False
print('x == y is',x==y)

# Output: x != y is True
print('x != y is',x!=y)

# Output: x >= y is False
print('x >= y is',x>=y)

# Output: x <= y is True
print('x <= y is',x<=y)
1
Python uses and and or conditionals.

i.e.

if foo == 'abc' and bar == 'bac' or zoo == '123':
  # do something
0
# logical and operator
# return first operands if false otherwise second operands

0 and 3
# output = 0
3 and 0 
# output = 0
3 and 5 
# output = 5
1

New to Communities?

Join the community