Learning python with stack overflow ...

·

2 min read

This is going to be an ever growing list of python questions and answers I found on stack overflow, providing a better understanding about python .

What does the "yield" keyword do in Python?

yield is a keyword that is used like return, except the function will return a generator. read more

What are metaclasses in Python?

Metaclasses are the 'stuff' that creates classes. read more

What are the differences between type() and isinstance() ?

isinstance caters for inheritance (an instance of a derived class is an instance of a base class, too), while checking for equality of type does not (it demands identity of types and rejects instances of subtypes, AKA subclasses). read more

Why do people write #!/usr/bin/env python on the first line of a Python script?

If you have several versions of Python installed, /usr/bin/env will ensure the interpreter used is the first one on your environment's $PATH. read more

If Python is interpreted, what are .pyc files?

CPython is designed to compile as fast as possible, as lightweight as possible, with as little ceremony as feasible -- the compiler does very little error checking and optimization, so it can run fast and in small amounts of memory, which in turns lets it be run automatically and transparently whenever needed, without the user even needing to be aware that there is a compilation going on, most of the time. read more

List comprehension vs map.

map may be microscopically faster in some cases (when you're NOT making a lambda for the purpose, but using the same function in map and a listcomp). List comprehensions may be faster in other cases and most (not all) pythonistas consider them more direct and clearer. read more

Difference between getattr and getattribute

A key difference between getattr and getattribute is that getattr is only invoked if the attribute wasn't found the usual ways. It's good for implementing a fallback for missing attributes, and is probably the one of two you want. read more

Overview of descriptor invocation