December 2018
Beginner to intermediate
796 pages
19h 54m
English
Unlike in most other languages, in Python it's very easy to return multiple objects from a function. This feature opens up a whole world of possibilities and allows you to code in a style that is hard to reproduce with other languages. Our thinking is limited by the tools we use, therefore when Python gives you more freedom than other languages, it is actually boosting your own creativity as well. To return multiple values is very easy, you just use tuples (either explicitly or implicitly). Let's look at a simple example that mimics the divmod built-in function:
# return.multiple.pydef moddiv(a, b): return a // b, a % bprint(moddiv(20, 7)) # prints (2, 6)
I could have wrapped the highlighted part in the preceding ...
Read now
Unlock full access