Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python operators

#PYTHON RELATIONAL OPERATORS
OPERATOR    DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
>	        Greater than	    a > b   gt(a, b)        __gt__(self, other)
>=	        Greater or equal to	a >= b  ge(a, b)        __ge__(self, other)
<	        Less than	        a < b   lt(a, b)        __lt__(self, other)
<=	        Less or equal to	a <= b  le(a, b)        __le__(self, other)
==	        Equal to	        a == b  eq(a, b)        __eq__(self, other)
!=	        Not equal to        a != b  ne(a, b)        __ne__(self, other)

#PYTHON MATHEMATICAL OPERATORS
OPERATOR	DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
+	        Addition	        a + b   add(a, b)       __add__(self, other)
–	        Subtraction	        a - b   sub(a, b)       __sub__(self, other)
*	        Multiplication	    a * b   mul(a, b)       __mul__(self, other)
/	        True Division	    a / b   truediv(a, b)   __truediv__(self, other)
//	        Floor Division	    a // b  floordiv(a, b)  __floordiv__(self, other)
%	        Modulo	            a % b   mod(a, b)       __mod__(self, other)
**	        Power	            a ** b  pow(a, b)       __pow__(self, other)

#PYTHON BITWISE OPERATORS
OPERATOR	DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
&	        Bitwise AND	        a & b   and_(a, b)      __and__(self, other)
|	        Bitwise OR	        a | b   or_(a,b)        __or__(self, other)
^	        Bitwise XOR	        a ^ b   xor(a, b)       __xor__(self, other)
~           Bitwise NOT         ~ a     invert(a)       __invert__(self)
>>          Bitwise R shift     a >> b  rshift(a, b)    __irshift__(self, other)
<<          Bitwise L shift     a << b  lshift(a, b)    __lshift__(self, other)
Comment

logical operators python

#Python (Basic) Logical Operators
------------------------------------------
OPERATOR  |  SYNTAX  |
----------------------
   and    |  a and b |
----------------------
#Example-----------------------------------
 if condition1 and condition2 and condition3:
 all_conditions_met == true
else:
 all_conditions_met == false
------------------------------------------
OPERATOR  |  SYNTAX  |
----------------------
   or	  |  a or b |
----------------------
#Example
if condition1 or condition2 or condition3:
 any_condition_met == true
else:
 any_condition_met == false

------------------------------------------
OPERATOR  |  SYNTAX  |
----------------------
   not	  |  not a |
----------------------
if not equal_to_condition:
 equal_to_condition == false
else:
 equal_to_condition == true
Comment

python operators

# --------------------------
# -- Arithmetic Operators --
# --------------------------
# [+] Addition
# [-] Subtraction
# [*] Multiplication
# [/] Division
# [%] Modulus
# [**] Exponent
# [//] Floor Division
# --------------------------

# Addition

print(10 + 30)  # 40
print(-10 + 20)  # 10
print(1 + 2.66)  # 3.66
print(1.2 + 1.2)  # 2.4

# Subtraction

print(60 - 30)  # 30
print(-30 - 20)  # -50
print(-30 - -20)  # -10
print(5.66 - 3.44)  # 2.22

# Multiplication

print(10 * 3)  # 30
print(5 + 10 * 100)  # 1005
print((5 + 10) * 100)  # 1500

# Division

print(100 / 20)  # 5.0
print(int(100 / 20))  # 5

# Modulus

print(8 % 2)  # 0
print(9 % 2)  # 1
print(20 % 5)  # 0
print(22 % 5)  # 2

# Exponent

print(2 ** 5)  # 32
print(2 * 2 * 2 * 2 * 2)  # 32
print(5 ** 4)  # 625
print(5 * 5 * 5 * 5)  # 625

# Floor Division

print(100 // 20)  # 5
print(119 // 20)  # 5
print(120 // 20)  # 6
print(140 // 20)  # 7
print(142 // 20)  # 7
Comment

python logical operators

not 
and 
or
Comment

Or Operator In Python

if 1==1 or 1==2:
    print("this is true")
#this is distinct from the || seen in some other languages
Comment

python logical operators code

children_above_five= True
have_good_health= True
if children_above_five and have_good_health:
    print("Eligible to get admission in Primary school.")
children_above_five= True
have_good_health= False
if children_above_five or have_good_health:
    print("Eligible to get admission in Primary school.")
children_above_five= True
have_good_health= False
if children_above_five and not have_good_health:
    print("Eligible to get admission in Primary school.")
Comment

using in as a logical operator in python

fruit = 'banana'
print('n' in fruit)     # Output: True
print('m' in fruit)     # Output: False
print('nan' in fruit)   # Output: True
if 'b' in fruit:
    print('Found it')   # Output: Found it
Comment

python operators

5 + 4 + 8 + 565 + 454.0 + 9 + 2 + 11 + 3 + 20 + 45 + 67
Comment

PREVIOUS NEXT
Code Example
Python :: how to delete whole list in python 
Python :: self keyword in python 
Python :: time conversion in python 
Python :: how to use python all() function to check a list is empty or not 
Python :: .save() in django 
Python :: python typing union 
Python :: python list pop equivalent 
Python :: csv to excel python 
Python :: python print an array 
Python :: python Parse string into integer 
Python :: python function arguments 
Python :: python sort based on multiple keys 
Python :: python print font size 
Python :: python round float to 2 decimals 
Python :: python modules list 
Python :: sorting in python 
Python :: Heroku gunicorn flask login is not working properly 
Python :: facet grid, barplot, catplot 
Python :: download pdf file python 
Python :: django model make the field caseinsensitive 
Python :: metodo de clase python 
Python :: wrds in python 
Python :: for 2d data compute standard deviation at each x 
Python :: explained_variance_ratio kernel pca 
Python :: Remove all duplicates words from a given sentence 
Python :: Python | Pandas MultiIndex.is_lexsorted() 
Python :: treesitter python languages 
Python :: jupyter notebook prevent open browser 
Python :: for count in range(size): 
Python :: How to download images from the OIDv4 in Anaconda Promt 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =