INFOSYS – Python Interview Questions
Here is the list of Python Interview Questions which are recently asked in Infosys company. These questions are included for both Freshers and Experienced professionals. Our Python Training has Answered all the below Questions.
1. What is Python?
Python is a high-level, interpreted, interactive and object-oriented scripting language that is used to create user interface applications for web development (server side), software development, mathematics, operation and so on.
Python is a general-purpose interpreted, interactive, object-oriented programming language.
2. Why can't I use an assignment in an expression?
The reason for not allowing assignment in Python expressions is a common, hard-to-find bug in those other languages, caused by this construct:
if (x = 0) {
...error handling...
}
else {
...code that only works for nonzero x...
}
The error is a simple typo: x = 0, which assigns 0 to the variable x, was written while the comparison x == 0 is certainly what was intended.3. Is there a toolto help find bugs or perform static analysis?
Pychecker and Pylint are the static analysis tools that help to find bugs in python. Pychecker is an open source tool for static analysis that detects the bugs from source code and warns about the style and complexity of the bug
4. How do you set a global variable in a function?
Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function. To create a global variable inside a function, you can use the global keyword
5. What are the rules for local and global variables in Python?
- In python, the variables referenced inside a function are global.
- When a variable is assigned new value anywhere in the body of a function then it is assumed as local.
- In a function, if a variable ever assigned new value then the variable is implicitly local and explicitly it should be declared as global.
Interview Questions based on Experience - Click here - Python Interview Questions and Answers
6. How can we create an empty class in Python?
In Python, to write an empty class pass statement is used. Pass is a special statement in Python that does nothing. It only works as a dummy statement. However, objects of an empty class can also be created.
7. What are the key features of Python?
Python is a dynamic, high level, free open source and interpreted programming language. It supports object-oriented programming as well as procedural oriented programming. In Python, we don't need to declare the type of variable because it is a dynamically typed language.
8. What is the difference between list and tuple in Python?
One of the most important differences between list and tuple is that list is mutable, whereas a tuple is immutable. This means that lists can be changed, and tuples cannot be changed.
9. List steps for setting up static files in Django?
- set STATIC_ROOT in settings.py
- run python2.7 manage.py collectstatic (or python3.5 or python3.6 as appropriate)
- Set up a Static Files entry on the PythonAnywhere Web tab.
10. What is Dogpile effect?
The Dogpile effect occurs when cache expires and websites are hit by numerous requests the same time. Dogpile effect can be prevented using semaphore lock.

11. How do I share global variables across modules?
In the update.py file, we import the config.py module and modify the values of a and b . Similarly, in the main.py file, we import both config.py and update.py module. Finally, we print and test the values of global variables whether they are changed or not.
12. How do we reverse a list in Python?
Reversing a list in-place with the list. reverse() method. Using the “[::-1]” list slicing trick to create a reversed copy. List comprehension and loop statement can also help.
13. How can Python be an interpreted language?
Python is called an interpreted language because it goes through an interpreter, which turns code you write into the language understood by your computer's processor. Python is an “interpreted” language. This means it uses an interpreter. An interpreter is very different from the compiler.
14. What do you understand by the term PEP 8?
PEP 8 stands for Python Enhancement Proposal which ,is Python's style guide. It's a set of rules for how to format your Python code to maximize its readability.
Writing code to a specification helps to make large code bases, with lots of writers, more uniform and predictable, too.
15. Define slicing in Python?
Python slicing is about obtaining a sub-string from the given string by slicing it respectively from start to end. Python slicing can be done in two ways.
slice() Constructor ,Syntax string[start:end:step] start, end and step have the same mechanism as slice() constructor.
16. How can I pass optional or keyword parameters from one function to another?
To pass the keywords from func() into funcy(),
def func (**kwargs):
print('func kwargs:', kwargs)
def funcy (a, b, c, **kwargs):
print('other args:', a, b, c)
print('keyword args:', kwargs)
def funcy(a, b, c, **kwargs):
print('other args:', a, b, c)
print('keyword args:', kwargs)
func(**kwargs)
17. How do you make a higher order function in Python?
A higher-order function accepts one or more functions as input and returns a new function. Sometimes it is required to use function as data. - To make high order function , we need to import functools module.
18. How do I copy an object in Python?
In Python, there are two ways to create copies :- Deep copy
- Shallow copy
19. How can I find the methods or attributes of an object?
Attributes of a class can also be accessed using the following built-in methods and functions:- getattr() – This function is used to access the attribute of object.
- hasattr() – This function is used to check if an attribute exist or not.
- setattr() – This function is used to set an attribute.
20. How do I convert a string to a number?
In Python an strings can be converted into a integer using the built-in int() function. The int() function takes in any python data type and converts it into a integer