2. OPERATORS:
The operator can be defined as a symbol which is responsible for a particular
operation between two operands. Operators are used to perform operations
on variables and values.
The operator can be defined as a symbol which is responsible for a particular
operation between two operands. Operators are used to perform operations
on variables and values.
Arithmetic operators
Comparison operators
Assignment Operators
Logical Operators
Membership Operators
Identity Operators
Types of Operators
3. Arithmetic Operators
Arithmetic operators are used with numeric values to perform common
mathematical operations:
Operator Name Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
// Floor division[Integer Division] x // y
** Exponentiation x ** y
% Modulus x % y
4. Arithmetic Operators
+ Addition x + y
Example 1:
A=10
B=20
C=A+B
print(“A+B=“,C)
--Output---
A+B=30
Example 2:
A=10
B=20
--Output---
A+B=30
print(“A+B=“,A+B)
Example 3:
A=int(input(“Enter value A:”))
print(“A+B=“,C)
B=int(input(“Enter value B:”))
C=A+B
--Output---
Enter value A: 5
Enter value B: 4
A+B=9
11. Expressions:
An expression is a combination of variable and operators. It generates a
single value, which by itself is an expression.
Example:
5 + 2 * 4 and the result is 13
Q. Convert the Mathematical Expressions to equivalent python expressions
Algebraic Expression Python Programming Expression
5A 5 * A
4ab 4 * a * b
A2 + B2 A**2 + B **2
a=(x+y)/(x-y)
12. 20 + 30 * 40
Evaluate the expressions:
1
2
20 + 120
140
20 - 30 + 40
1
2
-10 + 40
30
The two operators (–) and (+)
have equal precedence. Thus,
the first operator, i.e.,
subtraction is applied before
the second operator, i.e.,
addition (left to right).
14. + ( plus) and (*) sign for string
+ ( plus) : It is use to concatenation of string and in string case + (plus)
sign is known as concatenation operator.
Example:
If there are two variable A=‘WELCOME’ and B=‘PYTHON’ and we want
to join these two strings.
A=‘WELCOME’
B=‘PYTHON’
print(A+B)
---Output----
WELCOMEPYTHON
It display join or concatenation of
two string but without any gap
15. + ( plus) and (*) sign for string
* (multiply) : It is use to repeat the string as many times we need by
multiplying the string with number given.
Example:
If variable A=‘WELCOME’ and we want to display WELCOME 3 times
A=‘WELCOME’
print(A*3)
---Output----
WELCOMEWELCOMEWELCOME