0% found this document useful (0 votes)
2 views1 page

Python Programming Notes-21

The document provides an overview of Python programming concepts, specifically focusing on generator expressions and conditional expressions. It explains the syntax and behavior of these expressions, including examples of their usage. Additionally, it defines statements in Python, highlighting the assignment statement and control flow statements like if, while, and for.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python Programming Notes-21

The document provides an overview of Python programming concepts, specifically focusing on generator expressions and conditional expressions. It explains the syntax and behavior of these expressions, including examples of their usage. Additionally, it defines statements in Python, highlighting the assignment statement and control flow statements like if, while, and for.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON PROGRAMMING III YEAR/II SEM MRCET

Some of the python expressions are:

Generator expression:

Syntax: ( compute(var) for var in iterable )

>>> x = (i for i in 'abc') #tuple comprehension


>>> x
<generator object <genexpr> at 0x033EEC30>

>>> print(x)
<generator object <genexpr> at 0x033EEC30>

You might expect this to print as ('a', 'b', 'c') but it prints as <generator object <genexpr>
at 0x02AAD710> The result of a tuple comprehension is not a tuple: it is actually a
generator. The only thing that you need to know now about a generator now is that you
can iterate over it, but ONLY ONCE.

Conditional expression:

Syntax: true_value if Condition else false_value

>>> x = "1" if True else "2"

>>> x

'1'

Statements:

A statement is an instruction that the Python interpreter can execute. We have normally two
basic statements, the assignment statement and the print statement. Some other kinds of
statements that are if statements, while statements, and for statements generally called as
control flows.

Examples:

An assignment statement creates new variables and gives them values:

>>> x=10

16

You might also like