Questionnaire For Python Developer
Questionnaire For Python Developer
PEP stands for Python Enhancement Proposal. PEP 8 is especially important since it
documents the style guidelines for Python Code. Apparently contributing to the
Python open-source community requires you to follow these style guidelines sincerely
and strictly.
• A local scope refers to the local objects available in the current function.
• A global scope refers to the objects available throughout the code execution
since their inception.
• A module-level scope refers to the global objects of the current module
accessible in the program.
• An outermost scope refers to all the built-in names callable in the program. The
objects in this scope are searched last to find the name
Self is used to represent the instance of the class. With this keyword, you can access
the attributes and methods of the class in python. It binds the attributes with the given
arguments. self is used in different places and is often thought to be a keyword. But
unlike in C++, self is not a keyword in Python.
4. What is __init__?
xrange() and range() are quite similar in terms of functionality. They both generate a
sequence of integers, with the only difference that range() returns a Python list,
whereas, xrange() returns an xrange object.
Python library offers a feature - serialization out of the box. Serializing an object
refers to transforming it into a format that can be stored, so as to be able to
deserialize it, later on, to obtain the original object. Here, the pickle module comes
into play.
Pickling:
• Pickling is the name of the serialization process in Python. Any object in Python
can be serialized into a byte stream and dumped as a file in the memory. The
process of pickling is compact but pickle objects can be compressed further.
Moreover, pickle keeps track of the objects it has serialized and the serialization is
portable across versions.
• The function used for the above process is pickle.dump().
Unpickling:
Generators are functions that return an iterable collection of items, one at a time, in a
set manner. Generators, in general, are used to create iterators with a different
approach. They employ the use of yield keyword rather than return to return
a generator object.
Let's try and build a generator for Fibonacci numbers
• .py files contain the source code of a program. Whereas, .pyc file contains the
bytecode of your program. We get bytecode after compilation of .py file (source
code). .pyc files are not created for all the files that you run. It is only created for
the files that you import.
• Before executing a python program python interpreter checks for the compiled
files. If the file is present, the virtual machine executes it. If not found, it checks
for .py file. If found, compiles it to .pyc file and then python virtual machine
executes it.
• Having .pyc file saves you the compilation time.
GIL stands for Global Interpreter Lock. This is a mutex used for limiting access to
python objects and aids in effective thread synchronization by avoiding deadlocks. GIL
helps in achieving multitasking (and not parallel computing). The following diagram
represents how GIL works.
• Shallow copy does the task of creating new objects storing references of original
elements. This does not undergo recursion to create copies of nested objects. It
just copies the reference details of nested objects.
• Deep copy creates an independent and new copy of an object and even copies all
the nested objects of the original element recursively