Yield Keyword

The yield keyword is fundamental to the creation of generators. Consider the following generator function: def createGenerator(): print('Initial call') yield '1' print('Second call') yield '2' a = createGenerator() Calling the createGenerator() function will create a generator object stored as a. Note that the code inside the generator function will not be run yet. print(next(a)) # Initial call # 1 The first time the generator object is iterated over (in a loop or with next()), the function code will be run from the start until the first yield....

April 23, 2017 · 1 min · Rezha Julio

What are Generators?

Generators are special functions that implement or generate iterators. Generators are functions which behave like iterators, but can have better performance characteristics. These include: Creating values on demand, resulting in lower memory consumption. The values returned are lazily generated. Hence, it is not necessary to wait until all the values in a list are generated before using them. However, the set of generated values can only be used once. Generators look like normal functions, but instead of the return statement they make use of the yield statement....

April 21, 2017 · 1 min · Rezha Julio

Lambda Functions in Python

The lambda keyword in Python provides a shortcut for declaring small anonymous functions. Lambda functions behave just like regular functions declared with the def keyword. They can be used whenever function objects are required. For example, this is how you’d define a simple lambda function carrying out an addition: >>> add = lambda x, y: x + y >>> add(5, 3) 8 You could declare the same add function with the def keyword:...

April 16, 2017 · 5 min · Rezha Julio

Function in Python are First-Class Object

Python’s functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions. Grokking these concepts intuitively will make understanding advanced features in Python like lambdas and decorators (I will cover two this in the next post) much easier. It also puts you on a path towards functional programming techniques. In this post I’ll guide you through a number of examples to help you develop this intuitive understanding....

April 6, 2017 · 8 min · Rezha Julio

Django 1.11 Release Note a Reading

Django 1.11 is released for the world to use. It comes with a lot of changes, which can take some time to read. In this video, GoDjango read all of the release notes so you can just put on some headphones and hit play.

April 5, 2017 · 1 min · Rezha Julio