0% found this document useful (0 votes)
23 views14 pages

Advanced Python Session 1

The document covers advanced Python concepts including generators, descriptors, decorators, and comprehensions. Generators allow for on-the-fly value generation using the yield statement, while descriptors enable custom attribute access behavior. Decorators extend function behavior without modification, and comprehensions provide concise ways to create new sequences.

Uploaded by

umar farooq
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)
23 views14 pages

Advanced Python Session 1

The document covers advanced Python concepts including generators, descriptors, decorators, and comprehensions. Generators allow for on-the-fly value generation using the yield statement, while descriptors enable custom attribute access behavior. Decorators extend function behavior without modification, and comprehensions provide concise ways to create new sequences.

Uploaded by

umar farooq
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
You are on page 1/ 14

ADVANCED

PYTHON
Session 1
GENERATORS

Generators provide a way to generate values on the


fly as they’re needed without storing them in memory.
Example:
We use the yield statement in generators. This
statement yields a value to the caller and temporarily
suspends the execution of the generator until the next
value is requested.

It remembers its state and when resumed, the


function continues where it left off.
DESCRIPTORS
With descriptors, you can customize the attribute
access. It enables you to define custom behavior
when getting, setting & deleting attributes by defining
specific methods.
Example:
DECORATORS

A decorator allows us to wrap another function to


extend the behavior of the wrapped function, without
permanently modifying it.
Example:
COMPREHENSIONS

Comprehensions help us with a short and concise way


to create new sequences (such as lists, sets,
dictionaries, etc.).
List Comprehension:
Dictionary Comprehension:
Set Comprehension:
Generator Comprehension:
THANK YOU

You might also like