How well do you know Python?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jul 5 02:33:26 EDT 2016


On Tuesday 05 July 2016 14:02, Chris Angelico wrote:

> After some discussion with a Ruby on Rails programmer about where Ruby
> ends and where Rails begins (and it's definitely not where I'd have
> expected... Rails does a ton of monkey-patching, including of built-in
> types, to provide functionality that is strangely absent from the core
> language), I tried to come up with some somewhat-challenging Python
> questions. But to make them hard, I had to go a smidge more esoteric
[...]
> Got any other tricky questions to add?


Explain metaclasses, descriptors, the mro, multiple inheritance, and the 
interaction between them. Why is the mro needed?

obj.spam is a property. How do you get access to the underlying property object 
itself?

Why doesn't the property decorator work inside a Python 2 classic class?

Explain Python scoping rules, in particular with respect to nested classes and 
nested functions (or even nested classes inside nested functions).

Explain attribute lookup rules. When does an instance attribute take priority 
over a class attribute?

When is locals() writable? When is locals() writable, AND the effect shows up 
in the local scope? Explain how exec works inside a function, and the 
interaction with locals().

Name all the falsey builtins.

Apart from exceptions, list the builtins, from memory. You can list the 
exceptions as well.

An easy one: list the Python keywords.

What happens in this code snippet?

    L = [1]
    t = (L,)
    t[0] += 1

Explain what value t has, and why.

Explain what "yield from it" does and how it is different from:

    for item in it:
        yield item




-- 
Steve




More information about the Python-list mailing list