0% found this document useful (0 votes)
0 views

BCC-302 Unit1 Lecture 5

The document provides an overview of expressions in Python, detailing their definition as combinations of values, variables, and operators. It explains the difference between expressions and statements, introduces boolean expressions, and discusses how to create expressions using identifiers, literals, and operators. Additionally, it outlines the boolean values in Python and includes important questions for further understanding.

Uploaded by

Shashank Jaiswal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

BCC-302 Unit1 Lecture 5

The document provides an overview of expressions in Python, detailing their definition as combinations of values, variables, and operators. It explains the difference between expressions and statements, introduces boolean expressions, and discusses how to create expressions using identifiers, literals, and operators. Additionally, it outlines the boolean values in Python and includes important questions for further understanding.

Uploaded by

Shashank Jaiswal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Subject Name:-Python Programming

Subject Code:- BCC402


Unit No.:- 1
Lecture No.:- 3

Topic Name :- Expression in Python

Beerbal Solanki
Department of CS
BCC 302/ Unit-I 1
Content
1. Expression
2. Boolean expression

BCC 302/ Unit-I 2


Expression
• An expression is a combination of values,
variables, and operators. If you type an expression
on the command line, the interpreter evaluates it
and displays the result:
• >>> 1 + 12
• Operators and operands
• Operators are special symbols that represent
computations like addition and multiplication. The
values the operator uses are called operands.

BCC 302/ Unit-I 3


• The following are all legal Python expressions
whose meaning is more or less clear:
• 20+32 hour-1 hour*60+minute minute/60
5**2 (5+9)*(15-7)
• The symbols +, -, and /, and the use of
parenthesis for grouping, mean in Python
what they mean in mathematics. The asterisk
(*) is the symbol for multiplication, and ** is
the symbol for exponentiation.

BCC 302/ Unit-I 4


• Expressions are representations of value. They are
different from statement in the fact that statements do
something while expressions are representation of value.
For example any string is also an expressions since it
represents the value of the string as well.
• Python has some advanced constructs through which you
can represent values and hence these constructs are also
called expressions.
• In this tutorial you will get to know about:
• What are expressions in Python
• How to construct expressions.

BCC 302/ Unit-I 5


How to create an expressions

• Python expressions only contain identifiers, literals, and


operators
• Identifiers: Any name that is used to define a class,
function, variable module, or object is an identifier.
• Literals: These are language-independent terms in Python
and should exist independently in any programming
language. In Python, there are the string literals, byte
literals, integer literals, floating point literals, and
imaginary literals.
• Operators: In Python you can implement the following
operations using the corresponding tokens.
BCC 302/ Unit-I 6
BCC 302/ Unit-I 7
boolean expression

• A boolean expression (or logical expression)


evaluates to one of two states true or false. Python
provides the boolean type that can be either set
to False or True. Many functions and operations
returns boolean objects.
• The not keyword can also be used to inverse a
boolean type.
• >>> not True
• False

BCC 302/ Unit-I 8
• What is False ?
• Every object has a boolean value. The following
elements are false:
• None
• False
• 0 (whatever type from integer, float to complex)
• Empty collections: “”, (), [], {}
• Objects from classes that have the special method
__nonzero__
• Objects from classes that implements __len__ to return
False or zero,
BCC 302/ Unit-I 9
• A string in Python can be tested for truth
value.
• The return type will be in Boolean value (True
or False)
• Let’s make an example, by first create a new
variable and give it a value.

BCC 302/ Unit-I 10


BCC 302/ Unit-I 11
BCC 302/ Unit-I 12
BCC 302/ Unit-I 13
Important Questions
Q1. How can we create an expression.
Q2. what is boolean values.
Q3. what do you understand by boolean expression.
Q4. Define expression.
Q5. what are the false values in boolean expression.

BCC 302/ Unit-I 14


References
1. https://www.programiz.com/python-
programming
2. https://www.w3schools.com/python
3. https://www.python.org/doc/
4. Guido van Rossum and Fred L. Drake Jr, ―An
Introduction to Python – Revised and updated
for Python 3.2, Network Theory Ltd., 2011.
5. Timothy A. Budd, ―Exploring Python‖, Mc-
Graw Hill Education (India) Private Ltd.,, 2015.
BCC 302/ Unit-I 15
Thank You

BCC 302/ Unit-I 16

You might also like