Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

Questionnaire For Python Developer

PEP 8 is the style guide for Python code that contributors to the Python open-source community are expected to follow strictly. Scope in Python refers to the visibility and lifetime of variables - local, global, module-level, and outermost. Self represents the instance of a class and is used to access attributes and methods of the class. __init__ is a constructor method that is automatically called when a new object is created to allocate memory.

Uploaded by

Master fskm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Questionnaire For Python Developer

PEP 8 is the style guide for Python code that contributors to the Python open-source community are expected to follow strictly. Scope in Python refers to the visibility and lifetime of variables - local, global, module-level, and outermost. Self represents the instance of a class and is used to access attributes and methods of the class. __init__ is a constructor method that is automatically called when a new object is created to allocate memory.

Uploaded by

Master fskm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. What is PEP 8 and why is it important?

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.

2. What is Scope in Python?

• 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

3. What is the use of self in Python?

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__?

__init__ is a contractor method in Python and is automatically called to allocate


memory when a new object/instance is created. All classes have a __init__ method
associated with them. It helps in distinguishing methods and attributes of a class from
local variables.
5. Explain how can you make a Python Script executable on Unix?

• Script file must begin with #!/usr/bin/env python

6. How is memory managed in Python?

• Memory management in Python is handled by the Python Memory Manager.


The memory allocated by the manager is in form of a private heap
space dedicated to Python.
• Additionally, Python has an in-built garbage collection to recycle the unused
memory for the private heap space.

7. What is lambda in Python? Why is it used?

Lambda is an anonymous function in Python, that can accept any number of


arguments, but can only have a single expression. It is generally used in situations
requiring an anonymous function for a short time period. Lambda functions can be
used in either of the two ways:

8. What is the difference between xrange and range in Python?

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.

9. What is pickling and unpickling?

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:

• Unpickling is the complete inverse of pickling. It deserializes the byte stream to


recreate the objects stored in the file and loads the object to memory.
• The function used for the above process is pickle.load()

10. What are generators in Python?

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

11. What is PYTHONPATH in Python?

PYTHONPATH is an environment variable which you can set to add additional


directories where Python will look for modules and packages. This is especially useful
in maintaining Python libraries that you do not wish to install in the global default
location.

12. What is the difference between .py and .pyc files?

• .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.

13. Define GIL.

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.

14. Differentiate between deep and shallow copies.

• 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

You might also like