|
| 1 | +# Python Operators |
| 2 | + |
| 3 | +In Python, operators are special symbols that perform operations on values and variables. Here are the main types of operators and their definitions: |
| 4 | + |
| 5 | +## Arithmetic Operators |
| 6 | + |
| 7 | +Arithmetic operators are used to perform mathematical operations on numeric values. |
| 8 | + |
| 9 | +- **`+`**: Addition - Adds two values. |
| 10 | +- **`-`**: Subtraction - Subtracts one value from another. |
| 11 | +- **`*`**: Multiplication - Multiplies two values. |
| 12 | +- **`/`**: Division - Divides one value by another. |
| 13 | +- **`%`**: Modulus - Returns the remainder of a division. |
| 14 | +- **`**`**: Exponentiation - Raises one value to the power of another. |
| 15 | +- **`//`**: Floor Division - Divides one value by another and rounds down to the nearest whole number. |
| 16 | + |
| 17 | +## Assignment Operators |
| 18 | + |
| 19 | +Assignment operators are used to assign values to variables. They also allow you to perform an operation and assign the result to the same variable. |
| 20 | + |
| 21 | +- **`=`**: Assign - Assigns a value to a variable. |
| 22 | +- **`+=`**: Add and Assign - Adds a value to the variable and assigns the result to the variable. |
| 23 | +- **`-=`**: Subtract and Assign - Subtracts a value from the variable and assigns the result to the variable. |
| 24 | +- **`*=`**: Multiply and Assign - Multiplies the variable by a value and assigns the result to the variable. |
| 25 | +- **`/=`**: Divide and Assign - Divides the variable by a value and assigns the result to the variable. |
| 26 | +- **`%=`**: Modulus and Assign - Applies modulus operation and assigns the result to the variable. |
| 27 | + |
| 28 | +## Comparison Operators |
| 29 | + |
| 30 | +Comparison operators are used to compare two values and return a boolean result. |
| 31 | + |
| 32 | +- **`==`**: Equal to - Returns `True` if two values are equal. |
| 33 | +- **`!=`**: Not equal to - Returns `True` if two values are not equal. |
| 34 | +- **`>`**: Greater than - Returns `True` if the left value is greater than the right value. |
| 35 | +- **`<`**: Less than - Returns `True` if the left value is less than the right value. |
| 36 | +- **`>=`**: Greater than or equal to - Returns `True` if the left value is greater than or equal to the right value. |
| 37 | +- **`<=`**: Less than or equal to - Returns `True` if the left value is less than or equal to the right value. |
| 38 | + |
| 39 | +## Logical Operators |
| 40 | + |
| 41 | +Logical operators are used to perform logical operations and combine boolean values. |
| 42 | + |
| 43 | +- **`and`**: Logical AND - Returns `True` if both conditions are `True`. |
| 44 | +- **`or`**: Logical OR - Returns `True` if at least one condition is `True`. |
| 45 | +- **`not`**: Logical NOT - Returns `True` if the condition is `False`. |
| 46 | + |
| 47 | +## Identity Operators |
| 48 | + |
| 49 | +Identity operators are used to compare the memory location of two objects. |
| 50 | + |
| 51 | +- **`is`**: Is - Returns `True` if two variables point to the same object in memory. |
| 52 | +- **`is not`**: Is not - Returns `True` if two variables do not point to the same object in memory. |
| 53 | + |
| 54 | +## Membership Operators |
| 55 | + |
| 56 | +Membership operators are used to test if a value is a member of a collection (like a list, tuple, or set). |
| 57 | + |
| 58 | +- **`in`**: In - Returns `True` if a value is found in the collection. |
| 59 | +- **`not in`**: Not in - Returns `True` if a value is not found in the collection. |
| 60 | + |
| 61 | +## Bitwise Operators |
| 62 | + |
| 63 | +Bitwise operators perform operations on the binary representations of integers. |
| 64 | + |
| 65 | +- **`&`**: Bitwise AND - Performs AND operation on each bit of two numbers. |
| 66 | +- **`|`**: Bitwise OR - Performs OR operation on each bit of two numbers. |
| 67 | +- **`^`**: Bitwise XOR - Performs XOR operation on each bit of two numbers. |
| 68 | +- **`~`**: Bitwise NOT - Inverts the bits of the number. |
| 69 | +- **`<<`**: Bitwise left shift - Shifts the bits of a number to the left by a specified number of positions. |
| 70 | +- **`>>`**: Bitwise right shift - Shifts the bits of a number to the right by a specified number of positions. |
| 71 | + |
| 72 | +## Practice Questions and Resources |
| 73 | + |
| 74 | +- **Practice Questions**: [HackerRank Python Practice](https://www.hackerrank.com/domains/tutorials/10-days-of-python) |
| 75 | +- **YouTube Channel**: [My Python Playlist](https://www.youtube.com/playlist?list=PLX1eV90xXed2wujMJKUdsWQu2UMS9ROGO) |
| 76 | + |
| 77 | +Explore these resources to test your knowledge and enhance your programming skills! |
0 commit comments