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

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

|= operator python

>>> s1 = {"a", "b", "c"}
>>> s2 = {"d", "e", "f"}

>>> # OR, | 
>>> s1 | s2
{'a', 'b', 'c', 'd', 'e', 'f'}
>>> s1                                                     # `s1` is unchanged
{'a', 'b', 'c'}

>>> # In-place OR, |=
>>> s1 |= s2
>>> s1                                                     # `s1` is reassigned
{'a', 'b', 'c', 'd', 'e', 'f'}
Comment

// operator use in python

#One thing to note- since Python treats all numbers as floats (decimal numbers),
#you can use the double division sign // to get an integer.
#This is useful for finding indexes.
string1 = "abcde"  
middle = string1[len(string1) // 2]  # 4//2
print(middle) 
# c
Comment

operators in python

a = 3
b = 4

# Arithmetic Operators
print("The value of 3+4 is ", 3+4)
print("The value of 3-4 is ", 3-4)
print("The value of 3*4 is ", 3*4)
print("The value of 3/4 is ", 3/4)

# Assignment Operators
a = 34
a -= 12
a *= 12
a /= 12
print(a)

# Comparison Operators
# b = (14<=7)
# b = (14>=7)
# b = (14<7)
# b = (14>7)
# b = (14==7)
b = (14!=7)
print(b)

# Logical Operators
bool1 = True
bool2 = False
print("The value of bool1 and bool2 is", (bool1 and bool2))
print("The value of bool1 or bool2 is", (bool1 or bool2))
print("The value of not bool2 is", (not bool2))
Comment

python operators

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

PREVIOUS NEXT
Code Example
Python :: add two dataframes together 
Python :: what is chr function on python 
Python :: fetch image url discord py 
Python :: DIF_GCD solution 
Python :: pytesseract.image_to_data(img output_type=output.dict) 
Python :: mean pandas 
Python :: python looping over a list 
Python :: are tuples in python mutable 
Python :: how to open annaconda 
Python :: python coding practice 
Python :: python import from string name 
Python :: how to put space in between list item in python 
Python :: Convert Int to String Using format() method 
Python :: exception handling in tkinter 
Python :: join function python 
Python :: numpy arange 
Python :: extract numbers from list of strings python using regex 
Python :: how to delete a column in pandas dataframe 
Python :: wkhtmltopdf pdfkit blocked access to file 
Python :: for in print pyhton 
Python :: how to make a stopwatch in pythoon 
Python :: python cat 
Python :: how to check if how much time is your code taking to run in python 
Python :: convert rgb image to binary in pillow 
Python :: seaborn stripplot range 
Python :: Iterating With for Loops in Python 
Python :: how to form .cleaned data in class based views in django 
Python :: extract specific key values from python dictionary 
Python :: dataframe.fillna 
Python :: python string first letter uppercase and second letter in lowercase 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =