Monday, December 3, 2018

Questions for a Senior Python develoepr

A list of question to help you assess your Python seniority.

Questions
  • When will the else part of try-except-else be executed?
  • What are metaclasses in Python?
  • What is monkey patching? How to use in Python? Example?
  • What are the tools that help to find bugs or perform static analysis? What static code analyzers do you know/used?
  • Whenever Python exits, why isn’t all the memory de-allocated?
  • Explain how can you access a module written in Python from C? Vise versa?
  • What do these mean to you: @classmethod, @staticmethod, @property?
  • Is Python a functional language?
  • What is the attribute __slots__?
  • Is it possible to use the construction True = False?
  • How to create a class without the class statement?
  • Give an example of filter and reduce over an iterable object
  • Is it possible to have a producer thread reading from the network and a consumer thread writing to a file, really work in parallel? What about GIL?
  • How do you create a dictionary which can preserve the order of pairs?
  • What does Python's code optimization do?
  • What are descriptors? Code example?
  • What is MRO in Python? How does it work?
  • Mention what is the difference between Django, Pyramid, and Flask?
  • Identify the pitfalls/limitations in the function code.
  • Identify the pros and cons of the asynchronous code.
  • How to package code in Python?
  • What is wheels and eggs? What is the difference?
  • How to package binary dependencies in Python?
  • How can I reload a previously imported module?
  • What is the process of compilation and linking in python?
  • What id() function in Python is for?
  • What method is used to pass variables into function?

Code involving questions:
  • Explain how you reverse a generator?
  • Let A and B be objects of class Foo. What methods and in what order are called when "print (A + B)" is executed?
  • Place the following functions below in order of their efficiency. How would you test your answer?

    def f1(lIn):
        l1 = sorted(lIn)
        l2 = [i for i in l1 if i>0.5]
        return [i*i for i in l2]
    

    def f2(lIn):
        l1 = [i for i in lIn if i>0.5]
        l2 = sorted(l1)
        return [i*i for i in l2]
    

    def f3(lIn):
        l1 = [i*i for i in lIn]
        l2 = sorted(l1)
        return [i for i in l1 if i>(0.5*0.5)]
    
  • Write a one-liner that will count the number of capital letters in a file. Your code should work even if the file is too big to fit in memory.
  • Output? Why? Is this inheritance?

    class C:
        pass
    type (C ())
    type (C)
  • Explain the output:
    big_num_1   = 1000
    big_num_2   = 1000
    small_num_1 = 1
    small_num_2 = 1
    big_num_1 is big_num_2
    >>> False
    small_num_1 is small_num_2
    >>> True
    
  • How is this possible?
    _MangledGlobal__mangled = 23
    class MangledGlobal:
         def test(self):
             return __mangled
    >>> MangledGlobal().test()
    23
        

Inspired by this article.