Hi there, we’re Harisystems
"Unlock your potential and soar to new heights with our exclusive online courses! Ignite your passion, acquire valuable skills, and embrace limitless possibilities. Don't miss out on our limited-time sale - invest in yourself today and embark on a journey of personal and professional growth. Enroll now and shape your future with knowledge that lasts a lifetime!".
For corporate trainings, projects, and real world experience reach us. We believe that education should be accessible to all, regardless of geographical location or background.
1Python Operators
Operators are symbols or special functions in Python that allow you to perform various operations on values or variables. Python provides a wide range of operators for arithmetic, assignment, comparison, logical, and other operations. Let's explore some of the commonly used Python operators with examples.
Arithmetic Operators
Arithmetic operators are used to perform mathematical calculations on numeric values.
- Addition (+): Adds two values together. Example: 5 + 3 = 8
- Subtraction (-): Subtracts the second value from the first. Example: 10 - 4 = 6
- Multiplication (*): Multiplies two values. Example: 3 * 2 = 6
- Division (/): Divides the first value by the second (float division). Example: 10 / 3 = 3.3333
- Integer Division (//): Divides the first value by the second and returns the integer quotient. Example: 10 // 3 = 3
- Modulus (%): Returns the remainder of the division. Example: 10 % 3 = 1
- Exponentiation (**): Raises the first value to the power of the second. Example: 2 ** 3 = 8
Assignment Operators
Assignment operators are used to assign values to variables.
- =: Assigns the value on the right to the variable on the left. Example: x = 5
- +=: Adds the value on the right to the variable and assigns the result to the variable. Example: x += 3 (equivalent to x = x + 3)
- -=: Subtracts the value on the right from the variable and assigns the result to the variable. Example: x -= 2 (equivalent to x = x - 2)
- *=: Multiplies the variable by the value on the right and assigns the result to the variable. Example: x *= 2 (equivalent to x = x * 2)
- /=: Divides the variable by the value on the right and assigns the result to the variable. Example: x /= 4 (equivalent to x = x / 4)
- //=: Performs integer division on the variable and assigns the result to the variable. Example: x //= 2 (equivalent to x = x // 2)
- %=: Performs modulus division on the variable and assigns the remainder to the variable. Example: x %= 3 (equivalent to x = x % 3)
- **=: Raises the variable to the power of the value on the right and assigns the result to the variable. Example: x **= 2 (equivalent to x = x ** 2)
Comparison Operators
Comparison operators are used to compare two values and return a Boolean result (True or False).
- ==: Checks if the two values are equal. Example: 5 == 3 (False)
- !=: Checks if the two values are not equal. Example: 5 != 3 (True)
- >: Checks if the first value is greater than the second. Example: 5 > 3 (True)
- <: Checks if the first value is less than the second. Example: 5 < 3 (False)
- >=: Checks if the first value is greater than or equal to the second. Example: 5 >= 3 (True)
- <=: Checks if the first value is less than or equal to the second. Example: 5 <= 3 (False)
Logical Operators
Logical operators are used to combine multiple conditions and evaluate the result.
- and: Returns True if both conditions are True. Example: x > 0 and x < 10
- or: Returns True if either condition is True. Example: x > 0 or x < 10
- not: Returns the opposite of the condition. Example: not x > 0
Other Operators
Python also provides other operators such as membership operators (in and not in) and identity operators (is and is not), which are used for specific purposes.
Conclusion
Operators are essential in Python programming as they allow you to perform various operations on values and variables. By understanding and utilizing different operators, you can manipulate data, make decisions, and control the flow of your Python programs.
4.5L
Learners
20+
Instructors
50+
Courses
6.0L
Course enrollments
Future Trending Courses
When selecting, a course, Here are a few areas that are expected to be in demand in the future:.
Future Learning for all
If you’re passionate and ready to dive in, we’d love to join 1:1 classes for you. We’re committed to support our learners and professionals their development and well-being.
View CoursesMost Popular Course topics
These are the most popular course topics among Software Courses for learners