Skip to content

Instantly share code, notes, and snippets.

@sapamja
Last active August 29, 2015 13:57
Show Gist options
  • Save sapamja/9777510 to your computer and use it in GitHub Desktop.
Save sapamja/9777510 to your computer and use it in GitHub Desktop.
PYthon FAQ forum.

Dear all,

I am trying to start a FAQ kind of forum for python related questions.

All questions are mostly related to python version 2.7. Some question may not be applicable to 3.x and above.

  1. Why can't you delete a dictionary key while doing dict.iteritems() ?

  2. And why is it allow you to delete dictionary key while doing dict.items() ?

  3. Difference between a name startswith single underscore vs double underscore ?

  4. What is first class object in python ?

  5. How can you call a method by passing method name as argument ?

  6. Difference between __getattr__ and __getattribute__ ?

  7. Difference between __get__ and __getitem__ ?

  8. Is Descriptor different from Property Or descriptor is the generic form of Property, could you please explain ?

  9. What is the difference between locals() and vars() ?

  10. Can you prove python class is an object ? And what is metaclass ?

  11. Can you name some ducktyping feature implemented in python ?

  12. Is indexing on string and list i.e string[0] and list[0] are same?

  13. Difference between isinstance and type?

  14. Do you know python implement hash mapping ?

  15. Can you prove python function is a first class object ? Assuming you already know what is function and first class object ?

  16. Can you write a generator without using yields ?

  17. Write a class to add two object of class A, by overide __add__ methods ?

  18. Why doesn’t list.sort() return the sorted list?

  19. How can we write a goto statement in python ?

  20. What is Bound vs Unbound method, Class vs Static method in python?

  21. What is ducktyping and one implementation of python duck typing ?

  22. Tell me what is the output of the following snippet : (False, True)[True] and how it works ?

  23. Can you tell me the difference between ins_a and ins_b in the following snippet

    class A(object): def fun(self): pass ins_a = A.fun ins_b = A().fun

  24. Why membership lookup in set is much faster than list? can you explain how set is implemented in python ? Tell me one condition when list lookup is faster than set ?

  25. How can you prevent from generating python bytecode cached file i.e *.pyc file ?

  26. What are all these files represent *.pyc, *.pyo, *.py, *.pyd etc.

  27. How can you pass value to generator ?

  28. What is list overallocation and how it works ?

  29. Why must dictionary keys be immutable ?

  30. GIL is already implemented in python, So, why we need to implement locks in multithreaded programing for concurrency issue ? NB: Just to check is he clear with GIL with threads locks.

  31. Why am I getting an UnboundLocalError with the following snippets?

    >>> x = 10
    >>> def foo():
    ...     print x
    ...     x += 1
    
  32. How to use built in function type to create dynamic class ?

  33. Does __init__() return any value, if yes what it returns if not is it possible to return any value ? What __new__() returns ?

  34. How python object store the reference counter for garbage collection ?

  35. Difference between __add__ and __iadd__ ?

  36. How do you write a higher order function in Python?

  37. Is it possible to overide python class method at instance level ? If yes show me an example ? If no you are wrong.

  38. How to instantiate class using class name as string?

  39. What is free variable in python ? Can you give an example ?

  40. Explain context manager in python and how with statement works in python ?

Please share your answer and add more questions.

Thank You.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment