EXPRESSIONS IN PYTHON
An expression is a combination of values, i.e., constants, variables, and
operators. It generates a single value, which by itself is an expression.
For example,
2+3 here 2 and 3 are the operands and ‘+’ is an operator.
Converting mathematical expressions to equivalent Python expressions.
6B ---- 6*B
3bc+4 ---- 3*b*c+4
a=x+2
b-1 is equivalent to a=(x+2)/(b-1)
Operators: Operators are special symbols which represent computation. They
are applied on operand(s) which can be values or variables.
Operators are categorised as Arithmetic, Relational ,Logical and Assignment.
● Mathematical/Arithmetic Operators
Symbol Description Example 1 Example 2
+ Addition >>>55+45 >>>’Good’+’Morning’
100 GoodMorning
- Subtraction >>>55-45 >>>30-80
10 -50
* Multiplication >>>55*45 >>>’Good’*3
2475 GoodGoodGood
/ Division >>>17/5 >>>28/3
3.4 9.3333
% Remainder/Modulo >>>17%5 >>>23%2
2 1
** Exponentiation >>>2**3 >>>2**8
8 256
// Integer Division >>>7.0//2 >>>3//2
3.0 1
An expression is a combination of values, i.e., constants, variables, and
operators. It generates a single value, which by itself is an expression.
For example,
2+3 here 2 and 3 are the operands and ‘+’ is an operator.
Converting mathematical expressions to equivalent Python expressions.
6B ---- 6*B
3bc+4 ---- 3*b*c+4
a=x+2
b-1 is equivalent to a=(x+2)/(b-1)
Operators: Operators are special symbols which represent computation. They
are applied on operand(s) which can be values or variables.
Operators are categorised as Arithmetic, Relational ,Logical and Assignment.
● Mathematical/Arithmetic Operators
Symbol Description Example 1 Example 2
+ Addition >>>55+45 >>>’Good’+’Morning’
100 GoodMorning
- Subtraction >>>55-45 >>>30-80
10 -50
* Multiplication >>>55*45 >>>’Good’*3
2475 GoodGoodGood
/ Division >>>17/5 >>>28/3
3.4 9.3333
% Remainder/Modulo >>>17%5 >>>23%2
2 1
** Exponentiation >>>2**3 >>>2**8
8 256
// Integer Division >>>7.0//2 >>>3//2
3.0 1