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.
-
Why can't you delete a dictionary key while doing dict.iteritems() ?
-
And why is it allow you to delete dictionary key while doing dict.items() ?
-
Difference between a name startswith single underscore vs double underscore ?
-
What is first class object in python ?
-
How can you call a method by passing method name as argument ?
-
Difference between
__getattr__
and__getattribute__
? -
Difference between
__get__
and__getitem__
? -
Is Descriptor different from Property Or descriptor is the generic form of Property, could you please explain ?
-
What is the difference between locals() and vars() ?
-
Can you prove python class is an object ? And what is metaclass ?
-
Can you name some ducktyping feature implemented in python ?
-
Is indexing on string and list i.e string[0] and list[0] are same?
-
Difference between
isinstance
andtype
? -
Do you know python implement hash mapping ?
-
Can you prove python
function
is a first class object ? Assuming you already know what is function andfirst class object
? -
Can you write a generator without using
yields
? -
Write a class to add two object of class A, by overide
__add__
methods ? -
Why doesn’t list.sort() return the sorted list?
-
How can we write a
goto
statement in python ? -
What is Bound vs Unbound method, Class vs Static method in python?
-
What is ducktyping and one implementation of python duck typing ?
-
Tell me what is the output of the following snippet :
(False, True)[True]
and how it works ? -
Can you tell me the difference between
ins_a
andins_b
in the following snippetclass A(object): def fun(self): pass ins_a = A.fun ins_b = A().fun
-
Why membership lookup in
set
is much faster thanlist
? can you explain how set is implemented in python ? Tell me one condition whenlist
lookup is faster thanset
? -
How can you prevent from generating python bytecode cached file i.e *.pyc file ?
-
What are all these files represent *.pyc, *.pyo, *.py, *.pyd etc.
-
How can you pass value to generator ?
-
What is list overallocation and how it works ?
-
Why must dictionary keys be immutable ?
-
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.
-
Why am I getting an UnboundLocalError with the following snippets?
>>> x = 10 >>> def foo(): ... print x ... x += 1
-
How to use built in function
type
to create dynamic class ? -
Does
__init__()
return any value, if yes what it returns if not is it possible to return any value ? What__new__()
returns ? -
How python object store the reference counter for garbage collection ?
-
Difference between
__add__ and __iadd__
? -
How do you write a higher order function in Python?
-
Is it possible to overide python class method at instance level ? If yes show me an example ? If no you are wrong.
-
How to instantiate class using class name as string?
-
What is free variable in python ? Can you give an example ?
-
Explain context manager in python and how
with
statement works in python ?
Please share your answer and add more questions.
Thank You.