Python Expressions

Mastering Expressions in Python for Precise and Logical Execution

Apr 12, 2026

Python Expressions

An expression is a combination of operators and operands that is interpreted to produce some other value. In any programming language, an expression is evaluated as per the precedence of its operators. So that if there is more than one operator in an expression, their precedence decides which operation will be performed first. We have many different types of expressions in Python.


Constant Expressions

These are the expressions that have constant values only.

Example:

# Constant Expressions
x = 15 + 1.3
print(x)

Output:

16.3

Arithmetic Expressions

An arithmetic expression is a combination of numeric values, operators, and sometimes parenthesis. The result of this type of expression is also a numeric value. The operators used in these expressions are arithmetic operators like addition, subtraction, etc.


Integral Expressions

These are the kind of expressions that produce only integer results after all computations and type conversions.

Example:

# Integral Expressions
a = 12
b = 11.0
c = a + int(b)
print(c)

Output:

23

Floating Expressions

These are the kind of expressions which produce floating point numbers as result after all computations and type conversions.


Relational Expressions

In these types of expressions, arithmetic expressions are written on both sides of the relational operator (>, <, >=, <=). Those arithmetic expressions are evaluated first, and then compared as per relational operator and produce a boolean output in the end. These expressions are also called Boolean expressions.


Logical Expressions

These are kinds of expressions that result in either True or False. It basically specifies one or more conditions. For example, (10 == 9) is a condition if 10 is equal to 9. As we know it is not correct, so it will return False. Studying logical expressions, we also come across some logical operators which can be seen in logical expressions most often.


Bitwise Expressions

These are the kind of expressions in which computations are performed at bit level.


Combinational Expressions

We can also use different types of expressions in a single expression, and that will be termed as combinational expressions.

Example:

# Combinational Expressions
a = 16
b = 12
c = a + (b >> 1)
print(c)

Output:

22

Operator Precedence (Multiple operators in expression)

It's a quite simple process to get the result of an expression if there is only one operator in an expression. But if there is more than one operator in an expression, it may give different results on the basis of the order of operators executed. To sort out these confusions, the operator precedence is defined. Operator Precedence simply defines the priority of operators that which operator is to be executed first. The operator higher in the list has more precedence or priority:

Priority Operator Symbol
1 Parenthesis ( ) [ ] { }
2 Exponentiation **
3 Unary plus or minus, complement -a , +a , ~a
4 Multiply, Divide, Modulo / * // %
5 Addition & Subtraction +
6 Shift Operator >> <<
7 Bitwise AND &
8 Bitwise XOR ^
9 Bitwise OR |
10 Comparison Operators >= <= > <
11 Equality Operators == !=
12 Assignment Operators = += -= /= *=
13 Identity and membership operators is, is not, in, not in
14 Logical Operators and, or, not

So, if we have more than one operator in an expression, it is evaluated as per operator precedence. For example, if we have the expression "10 + 3 * 4". Going without precedence it could have given two different outputs 22 or 52. But now looking at operator precedence, it must yield 22.

Example:

# Operator Precedence
a = 10 + 3 * 4
print(a)
 
b = (10 + 3) * 4
print(b)
 
c = 10 + (3 * 4)
print(c)

Output:

22
52
22