• LOGIN
  • No products in the cart.

Python Interview Questions And Answers Updated 2020

What is Python? What are the benefits of using Python?

Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is open-source.

What is PEP 8?

PEP 8 is a coding convention, a set of recommendations, about how to write your Python code more readable.

What is pickling and unpickling?

Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using the dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.

How Python is interpreted?

Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed.

How memory is managed in Python?

  • 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 access to this private heap and the interpreter takes care of this Python private heap.
  • The allocation of Python heap space for Python objects is done by the Python memory manager. The core API gives access to some tools for the programmer to code.
  • Python also have an inbuilt garbage collector, which recycles all the unused memory and frees the memory and makes it available to the heap space.

What are the tools that help to find bugs or perform static analysis?

PyChecker is a static analysis tool that detects the bugs in Python source code and warns about the style and complexity of the bug. Pylint is another tool that verifies whether the module meets the coding standard.

python

What are Python decorators?

A Python decorator is a specific change that we make in Python syntax to alter functions easily.

What is the difference between list and tuple?

The difference between list and tuple is that list is mutable while tuple is not. Tuple can be hashed for e.g as a key for dictionaries.

How are arguments passed by value or by reference?

Everything in Python is an object and all variables hold references to the objects. The reference values are according to the functions; as a result, you cannot change the value of the references. However, you can change the objects if it is mutable.

What is Dict and List comprehensions are?

They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.

What are the built-in type does python provides?

There are mutable and Immutable types of Pythons built-in types Mutable built-in types

  • List
  • Sets
  • Dictionaries

Immutable built-in types

  • Strings
  • Tuples
  • Numbers

What is namespace in Python?

In Python, every name introduced has a place where it lives and can be hooked for. This is known as a namespace. It is like a box where a variable name is mapped to the object placed. Whenever the variable is searched out, this box will be searched, to get the corresponding object.

What is lambda in Python?

It is a single expression anonymous function often used as an inline function.

Why lambda forms in python does not have statements?

A lambda form in python does not have statements as it is used to make new function object and then return them at runtime.

What is a pass in Python?

Pass means, no-operation Python statement, or in other words, it is a place holder in a compound statement, where there should be a blank left and nothing has to be written there.

In Python what are iterators?

In Python, iterators are used to iterate a group of elements, containers like a list.

What is the unit test in Python?

A unit testing framework in Python is known as a unit test. It supports the sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections, etc.

In Python what is slicing?

A mechanism to select a range of items from sequence types like list, tuple, strings etc. is known as slicing.

What are the generators in Python?

The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function.

What is docstring in Python?

A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes.

What are local variables and global variables in Python?

Global Variables:

Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program.

Local Variables:

Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.

Example:

  • a=2
  • def add():
  • b=3
  • c=a+b
  • print(c)
  • add()
python

What is type conversion in Python?

Type conversion refers to the conversion of one data type into another.

  • int() – converts any data type into integer type
  • float() – converts any data type into float type
  • ord() – converts characters into integer
  • hex() – converts integers to hexadecimal
  • oct() – converts an integer to octal
  • tuple() – This function is used to convert to a tuple.
  • set() – This function returns the type after converting to set.
  • list() – This function is used to convert any data type to a list type.
  • dict() – This function is used to convert a tuple of order (key,value) into a dictionary.
  • str() – Used to convert an integer into a string.
  • complex(real,imag) – This function converts real numbers to complex(real,imag) number.

What are the built-in types of python?

Built-in types in Python are as follows –

  • Integers
  • Floating-point
  • Complex numbers
  • Strings
  • Boolean
  • Built-in
    functions

Explain how can you generate random numbers in Python?

To generate random numbers in Python, you need to import command as

import random

random.random()

This returns a random floating-point number in the range [0,1)

Explain how can you access a module written in Python from C?

You can access a module written in Python from C by following method,

Module = =PyImport_ImportModule(“<modulename>”);

Does Python have OOps concepts?

Python is an object-oriented programming language. It means that any program can be solved in python by creating an object model. However, Python can be treated as procedural as well as structural language.

How to remove values to a python array?

Array elements can be removed using pop() or remove() method. The difference between these two functions is that the former returns the deleted value whereas the latter does not.

Example:

  • a=arr.array('d', [1.1, 2.2, 3.8,
    3.1, 3.7, 1.2, 4.6])
  • print(a.pop())
  • print(a.pop(3))
  • a.remove(1.1)
  • print(a)
February 13, 2020
GoLogica Technologies Private Limited  © 2019. All rights reserved.