Skip to content

Commit a3a795e

Browse files
committed
describe generators
1 parent e700a34 commit a3a795e

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

.DS_Store

6 KB
Binary file not shown.

Generators.ipynb

+48-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
{
2-
"cells": [],
3-
"metadata": {},
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Python Generators"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"A Python generator is a function that produces a sequence of results. It works by maintaining its local state, so that the function can resume again exactly where it left off when called subsequent times. Thus, you can think of a generator as something like a powerful iterator.\n",
15+
"\n",
16+
"**Generator functions allow you to declare a function that behaves likes an iterator, allowing programmers to make an interator in a fast,easy, and clean way. An iterator is an object that can be iterated or looped upon. It is used to abstract a container of data to make it behave like an interable object. Examples of iterable objects that are used more commonly include list, dictionaries, and strings.\n",
17+
"\n",
18+
"**The state of generator functions are maintained through the use of the keyword yield and works much like using return, but it has some important differences.\n",
19+
"\n",
20+
"**The difference is that it saves the state of the function. The next time the function is called, execution continues from where it left off, with the same variable values it had before yielding.**"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": []
29+
}
30+
],
31+
"metadata": {
32+
"kernelspec": {
33+
"display_name": "Python 3",
34+
"language": "python",
35+
"name": "python3"
36+
},
37+
"language_info": {
38+
"codemirror_mode": {
39+
"name": "ipython",
40+
"version": 3
41+
},
42+
"file_extension": ".py",
43+
"mimetype": "text/x-python",
44+
"name": "python",
45+
"nbconvert_exporter": "python",
46+
"pygments_lexer": "ipython3",
47+
"version": "3.6.9"
48+
}
49+
},
450
"nbformat": 4,
551
"nbformat_minor": 2
652
}

0 commit comments

Comments
 (0)