<jupyter_start><jupyter_text>Python Operators are used to perform operations on variables and values.Python divides the operators in the following groups:1. Arithmetic operators2. Assignment operators3. Comparison operators4. Logical operators5. Identity operators6. Membership operators7. Bitwise operators ![py](img/Arithmetic Operators.JPG)<jupyter_code>from IPython.display import Image
Image(filename='img/Arithmetic Operators.jpg')<jupyter_output><empty_output><jupyter_text>Python Arithmetic operators<jupyter_code>2 + 3
x = 2
y = 3
z = x + y
print ("Addition of two numbers:", +z)
x = 2
y = 3
# z = x + y
print ("Addition of two numbers:", x+y)
x = "hello"
y = "world"
print("Addition of Two Strings is:", x+y)
print("Addition of Two Strings is:", 2+4)
a = int(input())
b = int(input())
c = a + b
print("Addition of two numbers:", +c, a+b)<jupyter_output>12
14
Addition of two numbers: 26 26<jupyter_text>Sub<jupyter_code>x = 2
y = 10
x-y
2 -3
x = -360
y = 225
z = x - y
print(z)
x = "hello"
y = "World"
z = x - y
print("Sub of two Strings," +z)<jupyter_output><empty_output><jupyter_text>MUL<jupyter_code>10*20
a = 20 
b = 30 
c = a*b
print(c)
a=50 
b = 100
print(a*b)<jupyter_output>5000<jupyter_text>DIV<jupyter_code># DIV OF TWO NUMBERS
a =62.9/3 
print(a)
z = 2.5 
x = 3.5
print(x/z)# because we are get float values as o/p
int(x/z)# int values
# moduler %
a = 6
b = 7
print(a%b)
50%2<jupyter_output><empty_output><jupyter_text>Floar Div<jupyter_code># Give input is int we will get as int
# If Give input is Float we will get Float
# float by float 
a =62.9//3.0
print(a) # we are geting float 
# int by float
c =63//3.0
print(c) # float
# int by int 
b = 62//3 
print(b) # we will get as int<jupyter_output>20.0
21.0
20<jupyter_text>Exp<jupyter_code># Exp **
a = 2
b = 2
c = a**b
print(c)
a = 10.2
b = 2
print(a**b)
a = 10
b = 2.2
print(a**b)
print(int(a**b))
print(int(a*b))<jupyter_output>158.48931924611142
158
22<jupyter_text>Assignment Operators<jupyter_code># Assignment operators are used to assign values to variables:
from IPython.display import Image
Image(filename='img/Assignment operators1.jpg')
x = 2
print(x)
x = 2.5
print(x)
x = "hello"
print(x)

x = 2
y = 3
x += y
x -= y
x *= y
x /= y
x//=y
x**=y
print(x)
x = 2
y = 3
x-=y
print(x)
x = 2
y = 3
x *=y
print(x)
a = 20
b = 3
a//=b
a
a = 2
b = 3
a**=b
a
v = 1
v += 3
print(v)
v -=5
print(v)

x= 2
x *= 4
print(x)
x= 2
x /= 4
print(x)
x= 4
x //= 2
print(x)
x= 2
x **= 4
print(x)
x= 2
x <<= 4
print(x)
x= 2
x >>= 4
print(x)
x= 2
x %= 4
print(x)
x= 2
x &= 4
print(x)
x= 2
x |= 4
print(x)
a= 2
a ^= 4 # x = x^4 
print(a)<jupyter_output>6<jupyter_text>Python Comparison operators are used to compare two values:<jupyter_code>from IPython.display import Image
Image(filename='img/Comparison operators.jpg')
# Equal operator is used for comparing x and y values in the variables.
x = 4
y = 4
print(x==y)
# NotEqual operator is used for comparing x and y values in the variables.
x = 4
y = 4
print(x!=y)
# greater Then operator is used for comparing x and y values in the variables if X is Grater then Y output will be Treu or else False.
x = 4
y = 3
print(x>y)
# Less then operator is used for comparing x and y values in the variables.
x = 4
y = 2
print(x<y)
# Lessthen or Equal operator is used for comparing x and y values in the variables.
x = 4
y = 3
print(x<=y)
# Grater then or Equal operator is used for comparing x and y values in the variables.
x = 4
y = 4


print(x>=y)
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)<jupyter_output>x > y  is False
x < y  is True
x == y is False
x != y is True
x >= y is False
x <= y is True<jupyter_text>Logical operators are used to combine conditional statements:<jupyter_code>from IPython.display import Image
Image(filename='img/Logical operators.jpg')
x = True
y = False

# We are appling logical on  X and y Output: x and y is False
print(x and y)

# We are appling logical on  X and y  Output: x or y is True
print(x or y)

# We are appling logical on  X and y  Output: not x is False
print(not y)<jupyter_output>False
True
True<jupyter_text>Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location:<jupyter_code>from IPython.display import Image
Image(filename='img/Identity operators.jpg')
z = eval(input()) # int, float, complex
z
a = input()
a

x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
# x3 = [1,2,3]
# y3 = [1,2,3]

# Output: False
print(x1 is not y1)

# Output: True
print(x2 is y2)

# # Output: False
# print(x3 is y2)
from IPython.display import Image
Image(filename='img/Membership operators.jpg')
x = 'Hello world'
y = [1,2,3,3,4,5,6]

# Output: True
print('H' in x)

# Output: True
print('True' not in x)

# Output: True
print(1 in y)

# Output: False
print('a' in y)
print(x.capitalize(),x.upper(),x.lower(),x.replace("e","a"),x.split(),x.strip(),x.casefold())
print(max(x))
print(min(x))<jupyter_output>True
True
True
False
Hello world HELLO WORLD hello world Hallo world ['Hello', 'world'] Hello world hello world
w<jupyter_text>Bitwise operators are used to compare (binary) numbers:<jupyter_code>from IPython.display import Image
Image(filename='img/Bitwise operators.jpg')
from IPython.display import Image
Image(filename='img/bin to hex.jpg')<jupyter_output><empty_output><jupyter_text>from IPython.display import ImageImage(filename='img/BitConversion.gif')<jupyter_code>from IPython.display import Image
Image(filename='img/Bit to bytes.png')
a = 6            # 6 = 0110
b = 1            # 1 = 0001 
c = 0            # 0 = 0000

# When we are using AND Bitwise Operation we have to Multiple two values 
Q = a & b        
print ("And Operation in bits", Q)

# WHEN WE ARE PERFORMING | BITWISE OR OPERATION WE HAVE  TO ADD THE TWO VALUES 
c = a | b       
print (c)

# 
c = a ^ b        
print (c)

c = ~a        
print (c)

c =2 << 1       
print (c)

c = a >> 2      
print (c)<jupyter_output>And Operation in bits 0
7
7
-7
4
1<jupyter_text>Operator PrecedenceThe precedence of the operators is important to find out since it enables us to know which operator should be evaluated first. The precedence table of the operators in python is given below.<jupyter_code>from IPython.display import Image
Image(filename='img/Operator Predecessor.jpg')
a = 20
b = 10
c = 15
d = 5
e = 0

e = (a + b) * c / d       #( 30 * 15 ) / 5
print ("Value of (a + b) * c / d is ",  e)

e = ((a + b) * c) / d     # (30 * 15 ) / 5
print ("Value of ((a + b) * c) / d is ",  e)

e = (a + b) * (c / d);    # (30) * (15/5)
print ("Value of (a + b) * (c / d) is ",  e)

e = a + (b * c) / d;      #  20 + (150/5)
print ("Value of a + (b * c) / d is ",  e)<jupyter_output>Value of (a + b) * c / d is  90.0
Value of ((a + b) * c) / d is  90.0
Value of (a + b) * (c / d) is  90.0
Value of a + (b * c) / d is  50.0
{'fraction_non_alphanumeric': 0.13656263239655417, 'fraction_numerical': 0.037847761615591016, 'mean_word_length': 3.6046814044213265, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '329211', 'license': 'MIT', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2808, 'n_words': 1024, 'path': '5.Python Operators.ipynb', 'repo_name': 'reddyprasade/PYTHON-BASIC-FOR-ALL', 'size': '7081'}