Namaste Friends!!! Welcome to my video Today In this video we will talk about Answers to 52 Python Developer Interview Questions I already made a video where I mentioned Which are the 52 questions that asked in Interview Rounds I gave 200+ interviews at that moment and in all those interviews these mentioned questions were usually asked today in this video I will tell you answers to those 52 questions how you should answer For your simplicity, I decided these questions in 4 parts The first part is about Mostly Asked Questions means those questions will gonna ask you for sure in any interview In every python developer interview, These questions are a must!! So you should definitely know about these questions the second part is about commonly asked questions these are some of the questions that you should know if you are a Python developer because they can be asked at any point in time the third part is about tricky questions means there could be a trick in answers for these questions people can cross-question these questions so you should know how to handle these tricky questions The fourth part is about advanced level questions or rarely asked questions which are asked from few people or at a very high level of the interview the first question is what is the Difference Between List and Tuple first of all, I wanna tell you, whenever you answer these questions Answer simultaneously don't tell all points of the list and then all points of tuple you should tell each point from both sides one by one first of all, I wanna tell you the main difference, which you must tell which is, the list is mutable and tuple is a immutable mutable means you can change its value means you can modify the values in the list but we can modify these values in a tuple that is the main difference in the difference between list and tuple there are other differences as well, but you should always tell this difference now lets talk about other difference list is mutable, tuple is immutable I already mentioned this then use a definition, e.g List is a container to contain different types of objects and is used to iterate objects. Tuple is also similar to list but contains immutable objects. then you should tell about syntax, because that is the main difference in list you will use [], in tuple you will use () List iteration is slower
Tuple processing is faster than List. Lists consume more memory as compared to tuple Operations like insertion and deletion are better performed.
Elements can be accessed better. 2. What is a Decorator? Explain With Example. first of all, I wanna tell you in simple language suppose you made a function generally, you will pass parameters as a,b,c or int, float or str but when you use function as a parameter and in return, you will get a function then it will be considered as a decorator In simple language, the definition would be A Decorator is just a function that takes another function as an argument, add some kind of functionality and then returns another function. All of this without altering the source code of the original function that you passed in. that's how you can tell about decorators but you should use an example as well means you can write a code and then explain its functionality that how the decorator is working here you can see in the example as well I create a function, then pass another function as a parameter then declared another function, which is returning that same function you can check it, now let's discuss how to call this function I created another function with the name SHOW then I write print Show worked inside it then there is a way to call that function or there is a different way to define it means we are passing a function as a parameter after running it, we are receiving this output first we will get decorator_func worked in output which means, wrapper function is not executed at this moment so no part of it will execute and thus print("decorator func worked") will work then it will print. then there is return wrapper func written which indicates to run wrapper function there is a print statement in it - wrapper function worked then wrapper function worked will be printed then we will again return a function this is the same function that we receive in parameter which is show() so in this, show() will execute means it will print - show worked so this is how decorator works there is an alternate way for it which is general way - by starting with @ symbol so we can write it in different way, which is this function is working in the same manner as the previous one but the way it is written is totally different so we will get this output in the same way as I mentioned earlier so you should tell all these things when asked in an interview You must know the working of the code and what is the proper definition 3. Difference Between List and Dict Comprehension if you know what is the difference btw list and dict, then that is a similar difference btw list and dict comprehensions there is a difference in syntax, else everything is quite similar so you must explain syntax you can check the syntax here there is a value in case of list comprehension in its syntax but there is a key-value pair in case of dict comprehension in its syntax this is the different in their syntax lets discuss a common way example generally, you use the append function to create a list similarly to creating a dictionary, you use this way but there is another way to write this which works in similar way in this example, everything is working in a similar manner, but the difference is in their syntax - In one, its values, in another, its key-value pair In one, we use [ ], in another, we use {} so that is the difference between list comprehension and dict comprehension so you can mention all these points in an interview 4. How is memory managed in python? first of all I wanna tell you in simple language that there is a private heap memory in python in which space allocation is done by Python memory manager so this is how it works how allocations should be done, how to use heap memory, Python Memory manager is responsible for it and this is how memory is managed in python you must also be aware of Garbage Collector & Garbage value you can mention that as well now let's discuss how and what you should tell in the interview Memory management in Python involves a private heap containing all Python objects and data structures. Interpreter takes care of Python heap and that the programmer has no access to it. The allocation of heap space for Python objects is done by Python memory manager. then you can tell about the garbage collector Python also has a build-in garbage collector which recycles all the unused memory. then you can tell about it's functions gc.enable() -Enables automatic garbage collection.
gc.disable() - Disables automatic garbage collection. so whenever someone ask you about memory management, you can tell all these things next ques is Difference Between Generators And Iterators firstly I will tell you in simple language, there is not exactly a difference It is like a subset All generators are iterators, But all iterators are not generator, now let me explain to you in the iterator, we can use the list again and again but we can use values from the generator only once that is the only main difference now let me tell you how you should tell this in interview Generators are iterators which can execute only
once. Every generator is an Iterator An iterator is an object which contains a countable number of values and it is used to iterate over iterable objects like list, tuples, sets, etc. the generator uses yield keyword, whereas list use iter and next keywords then you can give examples as well what is init keyword in python In python we can use init in two ways one is __int__.py file and another is __init__() function means it can be used as a file and as a function know lets discuss what exactly it is when there is any __init__.py file in a folder it means the folder is a python package means the whole folder can be treated as python package and vice versa it is like an indication that tells us whether a folder is a package or not and this file can/cannot be null let's talk about __init__()
so the way you use a constructor in java, c++ to initialize any element the same way, __init__() is used in python now let me tell you how you should tell this in interview The __init__.py file lets the Python interpreter know that a directory contains code for a Python module It can be blank Without one, you cannot import modules from another folder into your project The role of the __init__.py file is similar to the __init__ function in a Python class The file essentially the constructor of your package or directory without it being called such. and whenever you will tell about init(), you need to write a program for it you can see here 7. Difference Between Modules and Packages in Python in simple language, A module is just a .py file and collections of these modules in a folder is called Package Means, module is a file and the package is a folder now let me tell you how you should tell this in interview The module is a simple Python file that contains collections of functions and global variables and with having a .py extension file. It is an executable file and to organize all the modules we have the concept called Package in Python. you can also tell about how you can import these modules import <my_module> Import numpy, pandas lets discuss about the package The package is a simple directory having collections of modules. This directory contains Python modules and also having __init__.py file by which the interpreter interprets it as a Package. means if this .py file exist, then interpreter will interprets it as a package The package is simply a namespace. The package also contains sub-packages inside it. you can also mention, how you can import it from my_package.abc import a 8. Difference Between Range and Xrange? seriously I found this question very irrelevant, I always thought, Why do people ask this if you use Python 3 only, you never had an idea about Xrange() A similar thing happened to me, when I was learning Python, no one told me about xrange obviously, if you have never used python2, you won't have any idea about it but it is one of the most asked questions in an interview, so you must know this the main difference I already mentioned here, xrange was there in python2, but not in python 3 you can also mention other differences e.g