FIDELITY – Python Interview Questions

Here is the list of Python Interview Questions which are recently asked in Fidelity company. These questions are included for both Freshers and Experienced professionals. Our Python Training has Answered all the below Questions.

1. How to comment multiple lines in python?

Using multiple single # line comments. You can use # in Python to comment a single line: # THIS IS A SINGLE LINE COMMENT.

Using triple-quoted string literals. Another way to add multiline comments is to use triple-quoted, multi-line strings.

2. What are docstrings in Python?

A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object.

All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings.

3. What is the usage of help() and dir() function in Python?

Help() and dir(), are the two functions that are reachable from the python interpreter. Both functions are utilized for observing the combine dump of build-in-function. These created functions in python are truly helpful for the efficient observation of the built-in system.

4. What is a dictionary in Python?

Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key: value pair. Key value is provided in the dictionary to make it more optimized.

5. How can the ternary operators be used in python?

Ternary operators also known as conditional expressions are operators that evaluate something based on a condition being true or false.

It was added to Python in version 2.5. It simply allows to test a condition in a single line replacing the multiline if-else making the code compact.

6. What are the built-in types of python?

The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions. Some collection classes are mutable.

The methods that add, subtract, or rearrange their members in place, and don't return a specific item, never return the collection instance itself but None.

7. What do you understand by the term PEP 8?

PEP stands for Python Enhancement Proposal which is a design document that provides guidelines and best practices on how to write Python code. The primary focus of PEP 8 is to improve the readability and consistency of Python code.

8. What are Python Decorators?

Decorators are very powerful and useful tool in Python since it allows programmers to modify the behaviour of function or class.

Decorators allow us to wrap another function in order to extend the behaviour of the wrapped function, without permanently modifying it.

9. How can Python be an interpreted language?

Python is an “interpreted” language. This means it uses an interpreter. An interpreter is very different from the compiler. An interpreter executes the statements of code “one-by-one” whereas the compiler executes the code entirely and lists all possible errors at a time.

10. Explain the difference between local and global namespaces?

A global variable is a variable that is accessible globally. A local variable is one that is only accessible to the current scope, such as temporary variables used in a single function definition.

11. Define generators in Python?

A Python generator is a function that produces a sequence of results. It works by maintaining its local state, so that the function can resume again exactly where it left off when called subsequent times. Thus, you can think of a generator as something like a powerful iterator.

12. How to add values to a python array?

You can add a NumPy array element by using the append() method of the NumPy module. The values will be appended at the end of the array and a new ndarray will be returned with new and old values as shown above.

The axis is an optional integer along which define how the array is going to be displayed

Free PDF : Get our updated Python Course Content pdf

13. What are Python libraries? Name a few of them.

The Python standard library is an extensive suite of modules that comes with Python itself. Many additional libraries are available from PyPI (the Python Package Index).

NumPy. NumPy (Numerical Python) is a perfect tool for scientific computing and performing basic and advanced array operations. ...

SciPy. This useful library includes modules for linear algebra, integration, optimization, and statistics.

14. How to import modules in python?

Importing Modules

To make use of the functions in a module, you'll need to import the module with an import statement. An import statement is made up of the import keyword along with the name of the module. In a Python file, this will be declared at the top of the code, under any shebang lines or general comments.

15. Explain Inheritance in Python with an example.

Inheritance allows us to define a class that inherits all the methods and properties from another class. Parent class is the class being inherited from, also called base class.

Child class is the class that inherits from another class, also called derived class.

16. How are classes created in Python?

A Class is like an object constructor, or a "blueprint" for creating objects.
  • Create a Class. To create a class, use the keyword class
  • Create Object. Now we can use the class named MyClass to create objects
  • The self Parameter.
  • Modify Object Properties.
  • Delete Object Properties.
  • Delete Objects.

17. What is Polymorphism in Python?

Polymorphism in python defines methods in the child class that have the same name as the methods in the parent class. In inheritance, the child class inherits the methods from the parent class.

18. How can we debug a Python program?

In order to run the debugger just type c and press enter. As the same suggests, PDB means Python debugger. To use the PDB in the program we have to use one of its method named set_trace().

19. What is the difference between list and tuple in Python?

In Python, list and tuple are a class of data structure that can store one or more objects or values. A list is used to store multiple items in one variable and can be created using square brackets. Similarly, tuples also can store multiple items in a single variable and can be declared using parentheses.

20. How do you invoke the Python interpreter for interactive use?

Start the Python Interpreter

You can use it in a REPL (Read-Evaluate-Print-Loop) fashion. To enter interactive mode after running a script, you can pass –i before the script. The command python -c command [arg] … executes statements in command, and python -m module [arg]

21. What is Python String format and Python String replace?

Python String format() is a function used to replace, substitute, or convert the string with placeholders with valid values in the final string. It is a built-in function of the Python string class, which returns the formatted string as an output.

22. How can we debug a Python program?

To start the debugger from the Python interactive console, we are using run() or runeval(). To continue debugging, enter continue after the ( Pdb ) prompt and press Enter. If you want to know the options we can use in this, then after the ( Pdb ) prompt press the Tab key twice.

23. Define encapsulation in Python?

Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of wrapping data and the methods that work on data within one unit.

This puts restrictions on accessing variables and methods directly and can prevent the accidental modification of data

24. Write a program in Python to produce Star triangle.

rows = int(input("Enter the number of rows: "))  
# It is used to print the space  
k = 2 * rows - 2  
# Outer loop to print number of rows  
for i in range(0, rows):  
# Inner loop is used to print number of space  
for j in range(0, k):  
 print(end=" ")  
# Decrement in k after each iteration  
k = k - 1  
 # This inner loop is used to print stars  
for j in range(0, i + 1):  
print("* ", end="")  
# Downward triangle Pyramid  
# It is used to print the space  
k = rows - 2  
# Output for downward triangle pyramid  
for i in range(rows, -1, -1):  
# inner loop will print the spaces  
for j in range(k, 0, -1):  
print(end=" ")  
# Increment in k after each iteration  
 k = k + 1  
# This inner loop will print number of stars  
for j in range(0, i + 1):  
print("* ", end="")  

Book a Free Mock Interviews and Test your Python Knowledge with our Experts


Here we listed all Python Interview Questions and Answers which are asked in Top MNCs. Periodically we update this page with recently asked Questions, please do visit our page often and be updated in Python.

To become a Python Certified professional and join in your dream company, Enroll now for our Best Python Training. We help you to crack any level of Python Interviews and We offering Python Training with 100% Placements.