Operators in python programming are essential to perform various operations with more than one operands. For example, to perform addition operation between two the values of two variables we use addition operator. Similarly for subtraction we have subtraction operator. Lets know all these operator one by one.
Addition Operator +
Addition operator performs addition operation. The sign of addition operator is +
Subtraction Operator –
Subtraction operator performs subtraction operation. The sign of subtraction operator is –
Multiplication Operator *
Multiplication operator performs multiplication operation. The sign of multiplication operator is *
Division Operator /
Division operator performs division operation. The sign of division operator is /
Modulus Operator %
Modulus operator performs modulus operation. Modulus operation returns the remainder of division of two values. The sign for modulus operator is %
Note: Addition Operator, Subtraction Operator, Multiplication Operator, Division Operator and Modulus operator are also known as Arithmetic operators.
There are few more and very helpful operators exist in Python programming. They are listed below.
Assignment Operator =
Assignment operator assigns value to the variable. In one of the previous tutorial, I had mentioned about variable declaration. In variable declaration we have learned about assigning values. The sign for assignment operator is =
Addition Assignment Operator +=
Addition assignment operator adds the assigned value to the value of the variable. The sign for addition assignment operator is +=
Suppose a requirement comes to increase the value of the variable number by 500 and print the new value.
Using addition assignment operator
Subtraction Assignment Operator -=
Subtraction assignment operator deducts the assigned value from the value stored in the variable. The sign of subtraction assignment operator is -=
Deduct the value of number variable by 500.
Multiplication Assignment Operator *=
Multiplication Assignment Operator multiplies the assigned value with the value stored in a variable. The sign of multiplication assignment operator is *=
Increase the value of number variable by 5 times.
Division Assignment Operator /=
Division assignment operator divides the stored value in variable by assigned value. The sign of division assignment operator is /=
number = 1000
Print the one fourth value of the variable number
Modulus Assignment Operator %=
Modulus assignment operator returns the remainder after the division of the value stored in the variable with the assigned value. The sign of modulus assignment operator is %=
Print the remainder after division by 25.