paython article

The Job Interview

Job interviews can be stressful. Developer interviews especially. You might know the code like the back of your hand, but it’s a whole different thing when you have an interviewer putting you on the spot, judging your very existence. Sometimes you know how to use the code, but you don’t know the words in human-speak to explain what you know.

Here’s a couple things you’ll want to know how to explain using that old nearly-deprecated language, English..

Welcome back! In this installment of “human-speak for developers”, we go over some key questions about the language Python.

Python was created and released by Guido van Rossum in 1991. It is an interpreted, high-level, general-purpose programming language with a design philosophy that emphasizes code readability, notably using significant whitespace. Python provides constructs that enable clear programming on both small and large scales.

Python features a dynamic type system and automatic memory management, and supports multiple programming paradigms, including object-oriented, imperative, functional and procedural. It has a large and comprehensive standard library.

Python interpreters are available for many operating systems. CPython, the reference implementation of Python, is open source software and has a community-based development model, as do nearly all of Python's other implementations. Python and CPython are managed by the non-profit Python Software Foundation.

How does Python handle memory management?

Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap.

The allocation of Python heap space for Python objects is done by Python memory manager. The core API gives access to some tools for the programmer to code.

Python also has an inbuilt garbage collector, which recycle all the unused memory and frees the memory and makes it available to the heap space.

  1. What are the different types of inheritance in Python?

Single Inheritance – In this type of inheritance, derived class obtains the members of a particular super class.

Multi-Level Inheritance – In this type of inheritance, a derived class d1 is inheriting the properties of base class base1, and another derived class is inheriting the properties of base2.

Hierarchical Inheritance – In this type of inheritance, from single base class you can inherit many child classes

Multiple Inheritance – In this type of inheritance, a derived class is inheriting the properties of many base classes.

  1. How is Multi Threading Achieved in Python?

Python has a multi threading package called the Global Interpreter Lock (GIL). It is the work of the GIL to make sure that only one of the ‘threads’ can execute at any one point of time. Normally a thread accepts the GIL, does a little work, then passes it on the GIL to the next thread. All this happens very quickly, making it appear that threads are executing in parallel, but they are really just taking turns using the same CPU core. All this GIL passing adds overhead to execution, meaning it should be avoided if faster code execution is the goal.

  1. What are the different uses of help() and dir() functions in Python?

dir() and help(), both the functions are accessible from the Python interpreter and used are generally used for viewing a consolidated dump of built-in functions.

Dir() function: The dir() function is used to display the defined symbols.

Help() function: This function is mainly used to display the string of documentation, and allows the programmer to see the help related to modules, keywords, attributes, etc.

  1. Explain split(), sub(), subn() methods of “re” module in Python.

To modify the strings, Python’s “re” module is providing 3 methods. They are:

sub() – finds all substrings where the regex pattern matches and then replace them with a different string

split() – uses a regex pattern to “split” a given string into a list.

subn() – being similar to sub() it also returns the new string along with the number of replacements.

  1. What is the use of the ‘self’ keyword in Python?

In Python ‘self’ references the instance of the class.

  1. What are generators?

Generators are used in python to return an iterable object. It is used to modify the behavior of the loop statement. Loops can be replaced with generators to perform on large dataset efficiently.

  1. What is lambda in python?

Lambda is single line code block which can have multiple arguments. It behaves like a function without function name.

For example:

Cube = lambda x : x * x * x

  1. What is a negative indexing in python?

Python sequences are managed by integer values (-ve 0 -ve). They can be accessed both wise. Positive indices start with 0 and continue to 1, 2, 3, …. N and Negative indices start with -1 and point to the last index.

For example:

Name = “python”

Name[-1] /////// n

Name[:-1] ////// python

  1. What is monkey patching in python?

Monkey patching is a concept by which we can change the function behavior in runtime. Due to the dynamic nature of the python, we can replace the body of a class function to new one. It is very useful in testing the python application. For example, if we have any class method which returns some api data and during testing, we don’t want the api data and use some local data then we can change the function and assign another function to it.

  1. What are the differences between docstrings and comments?

Docstring refers to documentation string for a function. It must be defined at first, within a function that defines it. Though there’s not much difference between the two, one could put it this way– Docstrings are for documentation, however, comments are for code readers/reviewers.

  1. What are the rules for local and global variables in Python?

In Python, variables that are only called and declared inside a function become inherently global. But, If a variable is assigned a new value within the same function, it will then be a local variable.

But, you also have the flexibility of explicitly declaring a variable as "global" within the same function.

  1. Explain split(), sub(), subn() methods of “re” module in Python.

To modify the strings, Python’s “re” module is providing 3 methods. They are:

sub() – finds all substrings where the regex pattern matches and then replace them with a different string

split() – uses a regex pattern to “split” a given string into a list.

subn() – being similar to sub() it also returns the new string along with the number of replacements.

  1. What are the parameter passing mechanism in Python?

Pass by references: Every parameter (argument) is passed “by reference” to the functions by default. However, in case you modify the value of the parameter in the function, the impact can also be reflected in the called function.

Pass by value: The pass by value is that at whatever time you pass the parameters to functions which are of the type such as strings, numbers, tuples. This is due to the immutable nature of them.

  1. What are the rules for local and global variables in Python?

In Python, variables that are only called and declared inside a function become inherently global. But, If a variable is assigned a new value within the same function, it will then be a local variable.

However, there is also the flexibility of explicitly declaring a variable as "global" within the same function.