Cheatography
https://cheatography.com
This explains Iterators, Generators and decorators in one page
ITERATORS
Looping
Important functions to be implemented
__iter__()
__next__()
__iter__() : takes iteratable object like list, tuples
__next__(): is used to return the next value in iteration |
|
|
GENERATORS
1. Generator generate one element at a time from a sequence.
2. Yield is used to get the value
3 It saves the state not like function where once function is called state will be returned to new call |
List Comprehension vs Generation
Comprehension: all in one go
Generation : one by one ...fast |
|
|
DECORATORS
1. A decorator is a special function which adds some extra functionality to an existing function
2. A decorator is a function that accepts a function as a parameter and returns a function.
3. Decorators are useful to perform some additional processing required by a function. |
Want to add addition functionality to function
@decor
showvehicle = decor(showvehicle) instead of this line, you can use @decor |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by sahusourabh