Tuesday 7 February 2017

Python Interview Questions

1. What is Python? State some programming language features of Python.
What is Python? - Python is a modern powerful interpreted language with objects, modules, threads,
 exceptions, and automatic memory managements......



2. Explain how python is interpreted
How python is interpreted - Python program runs directly from the source code. Each type Python programs are
 executed code is required.......

3. What are the rules for local and global variables in Python?
Local and global variables - If a variable is defined outside function then it is implicitly global. If variable is assigned new value inside the function means it is local.......

4. What will be the output of the code below? Explain your answer.
def extendList(val, list=[]):
    list.append(val)
    return list

list1 = extendList(10)
list2 = extendList(123,[])
list3 = extendList('a')

print "list1 = %s" % list1
print "list2 = %s" % list2
print "list3 = %s" % list3

5. How would you modify the definition of extendList to produce the presumably desired behavior?
The output of the above code will be:

list1 = [10, 'a']
list2 = [123]
list3 = [10, 'a']
Many will mistakenly expect list1 to be equal to [10] and list3 to be equal to ['a'], thinking that the list argument will be set to its default value of [] each time extendList is called.

However, what actually happens is that the new default list is created only once when the function is defined, and that same list is then used subsequently whenever extendList is invoked without a list argument being specified. This is because expressions in default arguments are calculated when the function is defined, not when it’s called.

list1 and list3 are therefore operating on the same default list, whereas list2 is operating on a separate list that it created (by passing its own empty list as the value for the list parameter).

The definition of the extendList function could be modified as follows, though, to always begin a new list when no list argument is specified, which is more likely to have been the desired behavior:

def extendList(val, list=None):
  if list is None:
    list = []
  list.append(val)
  return list
With this revised implementation, the output would be:

list1 = [10]
list2 = [123]
list3 = ['a']

6. 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 an open source.

7. What is PEP 8?

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

8.  What is module and package in Python?

In Python, module is the way to structure program. Each Python program file is a module, which imports other modules like objects and attributes.

9.  Explain how you can access sessions in Flask?

A session basically allows you to remember information from one request to another.  In a flask, it uses a signed cookie so the user can look at the session contents and modify. The user can modify the session if only it has the secret key Flask.secret_key.

10.  Mention the use of the split function in Python?

The use of the split function in Python is that it breaks a string into shorter strings using the defined separator. It gives a list of all words present in the string.

11.  Mention five benefits of using Python?

Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc.
Python does not require explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically
Provide easy readability due to use of square brackets
Easy-to-learn for beginners
Having the built-in data types saves programming time and effort from declaring variables.

12.  Mention the use of // operator in Python?

It is a Floor Divisionoperator , which is used for dividing two operands with the result as quotient showing only digits before the decimal point. For instance, 10//5 = 2 and 10.0//5.0 = 2.0.

13.  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>”);

14.  What is the purpose of PYTHONPATH environment variable?
PYTHONPATH - It has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer.

15.  What is the purpose of PYTHONSTARTUP environment variable?
PYTHONSTARTUP - It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH.

Feeling overwhelmed with all the questions the interviewer might ask in your Python interview? Now it is time to go through a series of Python interview questions which covers different aspects of Python. It’s never too late to strengthen your basics. Learn Python from industry experts while working with real-life use cases.

We Besant Technologies in Chennai offers best software training and placement in evergreen technologies like Database Developer Training, DBA Training, BI & Data Warehousing Training, Web Designing Training, SAP Training, Java Training, Software Testing Training, Microsoft Training, Oracle Applications Training, Mobile Applications Training, Oracle Fusion Middleware Training, Cloud Computing Training, IBM Training, Other Training and more to the students.
We limit the batch size to provide very good interaction with each and everyone. We are having dedicated team for the students placement assistance. By giving expert level trainers who are working in top MNC’s we do prepare the students for their job.
After getting trained at Besant Technologies Chennai you will be able to get vast experience by transforming your ideas into actual new application and software controls for the websites and the entire computing enterprise. To make it easier for you Besant Technologies at Chennai is visualizing all the materials you want.


                    Try not to have a GOOD TIME...This is Supposed to be Educational.

No comments:

Post a Comment