Python supports the following types of expression:
Infix Expression
In Infix expression, the operator is placed in between the operands.
For example, a=b-c
Prefix Expression
In the Prefix expression, the operator is placed before the operands.
For example, a=+bc
Postfix Expression
In Postfix expression, the operator is placed after the operands..
For example, a=bc+
Actually, Prefix and Postfix expressions are usually used in computers and can be easily evaluated using stacks.
Based on the data type of the result obtained on evaluating an expression:
Python supports the following type of expression.
Constant Expression
This expression involves only constants.
Example
print(5+7-2)
Output:
10
Integer Expression
Integer expression produces an integer result after evaluating the expression.
Example
a=10 b=5 c=a*b print(c)
Output:
50
Floating-point expression
Produces a floating-point result after evaluating the expression
Example
a=8 b=3 c=3 d=a+b+c/2 print(d)
Output:
12.5
Relational Expression
Relational expression produces a boolean result(either True or False) after evaluating
the expression
Example
year=2019 if(year%100==0): if(year%400==0): print("The year is a Leap year") else: print("The year is not a Leap year") else: if(year%4==0): print("The year is a Leap year") else: print("The year is not a Leap year")
Output:
The year is not a Leap year
Logical Expression
Logical expression combines two or more relational expressions and returns a value as True
or False
Example
a=90 b=70 c=120 if(a>b and a>c): print("First number is maximum") elif(b>a and b>c): print("Second number is maximum") else: print("Third number is maximum")
Output:
Third number is maximum
Bitwise Expression
Bitwise expression manipulates data at the bit level.
x=20 y=10 z=x&y print(z)
Output:
8
Assignment Expression
This expression is used to assign a value to a variable.
Example
x=20 y=10 z=x+y print(z)
Output:
30
Leave a comment