We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9
Name : Ravi Anand
Makaut Roll No : 14542723072
Subject : Python Programming Subject code : BCA301 Topic : Python Operator’s Introduction to Python Operators Operators are special symbols or These operators are essential for keywords in Python that perform manipulating data, making decisions, operations on variables and values and performing calculations in Python programs.
Python provides a variety of
operators for performing arithmetic, comparison, logical, and bitwise operations. Arithmetic Operators • Addition (‘+’): Adds two values. In this example, ‘a + b’ results in 13.
• Subtraction (‘-’): Subtracts one value from another.
Here, ‘a – b’ results in 7.
• Multiplication (‘*’): Multiplies two values. In this case,
‘a * b’ equals 30.
• Division (‘/’): Divides one value by another. ‘a / b’
results in approximately 3.33.
• Floor Division (‘//’): Divides and rounds down to the
nearest whole number. ‘a // b’ results in 3
• .Modulus (‘%’): Gives the remainder of the division. ‘a
% b’ results in 1.
• Exponentiation (‘**’): Raises one value to the power of
another. ‘a ** b’ results in 1000 Comparison Operators • Equal to (‘==‘): Checks if two values are equal. Here, ‘x == y’ returns False.
• Not equal to (‘!=‘): Checks if two values are not equal.
x != y returns True.
• Greater than (‘>’): Checks if one value is greater than
another. ‘x > y’ returns False.
• Less than (‘<‘): Checks if one value is less than
another. ‘x < y’ returns True.
• Greater than or equal to (‘>=‘): Checks if one value is
greater than or equal to another. ‘x >= y’ returns False.
• Less than or equal to (‘<=‘): Checks if one value is less
than or equal to another. ‘x <= y’ returns True. Logical Operators • Equal to (‘==‘): Checks if two values are equal. Here, ‘x == y’ returns False.
• Not equal to (‘!=‘): Checks if two values are not equal.
x != y returns True.
• Greater than (‘>’): Checks if one value is greater than
another. ‘x > y’ returns False.
• Less than (‘<‘): Checks if one value is less than
another. ‘x < y’ returns True.
• Greater than or equal to (‘>=‘): Checks if one value is
greater than or equal to another. ‘x >= y’ returns False.
• Less than or equal to (‘<=‘): Checks if one value is less
than or equal to another. ‘x <= y’ returns True. Bitwise Operators • ‘&’ (AND): Performs a bitwise AND operation. ‘x & y’ results in 1, because the binary 101 AND 011 equals 001.
• ‘|’ (OR): Performs a bitwise OR operation. ‘x | y’ results
results in 6, because the binary 101 XOR 011 equals 110.
• ‘~’(NOT): Inverts the bits. ‘~x’ results in -6, which is the
inverted binary of 5.
• ‘<<‘ (Left Shift): Shifts the bits to the left. ‘x << 1’ results in 10, which is 1010 in binary.
• ‘>>’ (Right Shift): Shifts the bits to the right. ‘x >> 1’
results in 2, which is 10 in binary. Assignment Operators • ‘=‘(Assignment): Assigns a value to a variable. ‘x = 10’ sets ‘x’ to ’10’.
• ‘+=‘(Add and Assign): Adds a value to the variable and
assigns the result. ‘x += 5’ increases ‘x’ by ‘5’, making it ’15’.
• ‘-=‘(Subtract and Assign): Subtracts a value from the
variable and assigns the result. ‘x -= 3’ decreases ‘x’ by ‘3’, making it ’12’.
• ‘*=‘ (Multiply and Assign): Multiplies the variable by a value
and assigns the result. ‘x *= 2’ doubles ‘x’ to ’24’.
• ‘/=‘ (Divide and Assign): Divides the variable by a value and
assigns the result. ‘x /= 4’ divides ‘x’ by ‘4’, resulting in ‘6.0’. Bibliography • ChatGPT: Assisted with generating content and examples for the presentation.
• Python.org: General reference for Python operators and documentation.