0% found this document useful (0 votes)
20 views16 pages

L05 - Expressions

Python

Uploaded by

tomerfai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views16 pages

L05 - Expressions

Python

Uploaded by

tomerfai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

DR.

APJ ABDUL KALAM TECHNICAL UNIVERSITY

Branch - CSE
Python Programming

Lecture – 5

Expressions
By

Mr. Aditya Tandon


Assistant Professor
Department of Computer Science and Engineering
Krishna Engineering College, Ghaziabad
11/09/2024 Python Programming 1
What is a Python Operator?
• A Python operator is a symbol that tells
the interpreter to perform certain
mathematical or logical manipulation.
• In simple terms, we can say Python
operators are used to manipulating data
and variables.
• In programming universe, operators
represent computations and conditional
resemblance.
What is an Expression?
• 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 different types of expression in Python. They are as follows:
• Constant Expressions
• Arithmetic Expressions
• Integer Expressions
• Floating Point Expressions
• Relational Expressions
• Logical Expressions
• Bitwise Expressions
• Combinational Expressions
Constant Expressions
• These are the expressions that have constant values only.

• 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. Here
are some operators in Python:
Operator
Syntax Functioning
s
+ x+y Addition
- x–y Subtraction
* x*y Multiplication
/ x/y Division
// x // y Floor (Integer) Division
% x%y Remainder
** x ** y Exponentiation
3333333333333335

Arithmetic Expressions

• Output:
52
28
480
3.3333333333333335
Integer Expressions
• There are the kind of expressions that produce only integer results after all computations
and type conversions.

• Output: 25
Floating point Expressions
• These are the kind of expressions which produce floating point numbers as result after all
computations and type conversions.

• Output: 2.6
Relational Expressions
• In these types of expressions, arithmetic expressions are written on both sides of
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.

• Output: True
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. Here are
some logical operators in Python:

Operator Syntax Functioning


and P and Q It returns true if both P and Q are true otherwise returns false.
or P or Q It returns true if at least one of P and Q is true.
not not P It returns true if condition P is false.
Logical Expressions
Output:
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.
Operator Precedence
Precedence Name Operator
• When we 1 Parenthesis () [] {}
combine 2 Exponentiation **
different types 3 Unary plus or minus, complement -a, +a, ~a
of expressions
4 Multiply, Divide, Modulo / * // %
or use
5 Addition & Subtraction +-
multiple
6 Shift Operators >> <<
operators in a
single 7 Bitwise AND &
expression, 8 Bitwise XOR ^
operator 9 Bitwise OR |
precedence 10 Comparison Operators >= <= > <
comes into 11 Equality Operators == !=
play. 12 Assignment Operators = += -= /= *= //= %=
13 Identity and membership operators is, is not, in, not in
14 Logical Operators and, or, not
Operator Precedence
• 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.
• Let’s discuss this with the help of a
Python program 
THANK YOU

11/09/2024 Python Programming 16

You might also like