Hoon
0
Q:

logical operators in python

#** is the exponent symbol in Python, so:
print(2 ** 3)
#output: 8
4
# 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
condition1 and condition2
condition1 or condition2
not condition
1
# Syntax for Boolean expression with or in Python
exp1 or exp2
6
% : Modulus - remainder of the division of left operand by the right
  	x % y (remainder of x/y)
2
//	'a' // 'b'	(Floor Division) Quotient when 'a' is divided by 'b', rounded to the next smallest whole number
5
# operations in numbers with python 
a = 15
b = 3
#a and b are not expression because they are at the right side

print(a + b)    # this will add the numbers
print(a - b)    # this will subtract the numbers
print(a * b)    # this will multiply the numbers
print(a / b)    #this will divide the numbers
print(a // b)   #this will gives the reminder after division
2
Python uses and and or conditionals.

i.e.

if foo == 'abc' and bar == 'bac' or zoo == '123':
  # do something
0
x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625
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
x > y is False
x < y is True
x == y is False
x != y is True
x >= y is False
x <= y is True
-1

New to Communities?

Join the community