Q:

python logical operators

# 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
//	'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
# Below follow the math operators that can be used in python
# ** Exponent	
2 ** 3 # Output: 8
# % Modulus/Remaider	
22 % 8 # Output: 6
# // Integer division	
22 // 8 # Output: 2
# / Division	
22 / 8 # Output: 2.75
# * Multiplication	
3 * 3 # Output: 9
# - Subtraction	
5 - 2 # Output: 3
# + Addition	
2 + 2 # Output: 4
1
Python uses and and or conditionals.

i.e.

if foo == 'abc' and bar == 'bac' or zoo == '123':
  # do something
0
# Below follow the comparison operators that can be used in python
# == Equal to
42 == 42 # Output: True
# != Not equal to
'dog' != 'cat' # Output: True
# < Less than
45 < 42 # Output: False
# > Greater Than
45 > 42 # Output: True
# <= Less than or Equal to
40 <= 40 # Output: True
# >= Greater than or Equal to
39 >= 40 # Output: False
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