50 python interview questions and answers

          

Python interview questions and answers


Part 1   Part 2   Part 3   Part 4   Part 5
Python interview questions - June 11, 2010 at 15:30 PM
1.What is Python? State some programming language features of Python.

Python is a modern powerful interpreted language with objects, modules, threads, exceptions, and automatic memory managements.................
Read answer

2.Explain how python is interpreted.

Python program runs directly from the source code. Each type Python programs are executed code is required.................
Read answer

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

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................
Read answer

4.Explain the dictionary in Python.

Python's built-in data type is dictionary, which defines one-to-one relationships between keys and values................
Read answer

5.How do we share global variables across modules in Python?

We can create a config file & store the entire global variable to be shared across modules or script in it. By simply importing config, the entire global variable defined it will be available for use in other modules..............
Read answer

6.How can we pass optional or keyword parameters from one function to another in Python?

Gather the arguments using the * and ** specifiers in the function's parameter list. This gives us positional arguments as a tuple and the keyword arguments as a dictionary..............
Read answer

7.Explain indexing and slicing operation in sequences

Different types of sequences in python are strings, Unicode strings, lists, tuples, buffers, and xrange objects............
Read answer

8.What is a Lambda form? Explain about assert statement?

The lambda form: Using lambda keyword tiny anonymous functions can be created.............
Read answer

9.Explain the role of repr function.

Python can convert any value to a string by making use of two functions repr() or str(). The str() function returns representations of values which are human-readable, while repr() generates representations which can be read by the interpreter.................
Read answer

10.Explain pickling and unpickling.

pickle is a standard module which serializes & de-serializes a python object structure................
Read answer

11.What is LIST comprehensions features of Python used for?

LIST comprehensions features were introduced in Python version 2.0, it creates a new list based on existing list...............
Read answer

12.How is memory managed in python?

Memory management in Python involves a private heap containing all Python objects and data structures. Interpreter takes care of Python heap and that the programmer has no access to it..............
Read answer

13.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................
Read answer

14.Explain how to copy an object in Python.

There are two ways in which objects can be copied in python.
Shallow copy & Deep copy...............
Read answer

15.How can I find the methods or attributes of an object in python?

Built-in dir() function of Python ,on an instance shows the instance variables as well as the methods and class attributes defined by the instance's class and all its base classes alphabetically. So by any object as argument to dir() we can find all the methods & attributes of the object’s class................
Read answer

16.How do I convert a string to a number?

Python contains several built-in functions to convert values from one data type to another data type............
Read answer

17.What is a negative index in python?

Python arrays & list items can be accessed with positive or negative numbers (also known as index)................
Read answer

18.How do you make an array in Python?

The array module contains methods for creating arrays of fixed types with homogeneous data types. Arrays are slower then list..............
Read answer

19.Explain how to create a multidimensional list.

There are two ways in which Multidimensional list can be created: By direct initializing the list as shown below to create multidimlist below.............
Read answer

20.Explain how to overload constructors (or methods) in Python.

_init__ () is a first method defined in a class. when an instance of a class is created, python calls __init__() to initialize the attribute of the object................
Read answer

21.Describe how to send mail from a Python script.

The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine.................
Read answer

22.Describe how to generate random numbers in Python.

Thee standard module random implements a random number generator.  There are also many other in this module, such as:...............
Read answer

23.How do we make python scripts executable?

Python scripts can be executed in two ways: Suppose I want to execute script1.py
We can open the script1.py in IDE editor & run the script in the frontmost window of the python IDE by hitting the run all button...............
Read answer

24.Explain how to make Forms in python.

As python is scripting language forms processing is done by Python. We need to import cgi module to access form fields using FieldStorage class.................
Read answer

25.Describe how to implement Cookies for Web python.

A cookie is an arbitrary string of characters that uniquely identify a session. Each cookie is specific to one Web site and one user................
Read answer

26.Describe how to use Sessions for Web python.

Sessions are the server side version of cookies. While a cookie preserves state at the client side, sessions preserves state at server side..............
Read answer

27.Describe how exceptions are handled in python.

Errors detected during execution of program are called exceptions. Exceptions can be handled using the try..except statement. We basically put our usual statements within the try-block and put all our error handlers in the except-block...............
Read answer

28.What is used to create Unicode string in Python?

Unicode is a system to represent characters from all the world's different languages. Two methods can be used to create unicode string:.................
Read answer

29.When to use list vs. tuple vs. dictionary vs. set?

List is like array, it can be used to store homogeneous as well as heterogeneous data type (It can store same data type as well as different data type)............
Read answer

30.Explain the disadvantages of python

Disadvantages of Python are: Python isn't the best for memory intensive tasks. Python is interpreted language & is slow compared to C/C++ or java..............
Read answer

Latest ASP.NET interview questions

What is partial classess in .net?
What is the Pre-Compilation feature of ASP.NET 2.0?
How can we create custom controls in ASP.NET?
Describe SAO architecture of Remoting.
Briefly explain how to specify remoting parameters using config files.
What is marshalling? Explain types of marshalling.

Latest AJAX interview questions

What are the benefits of AJAX over Java applet?
What is the disadvantage of AJAX?
What is synchronous request in AJAX?
Is the server or the client in control in AJAX?
Are there Usability Issues with AJAX?

Write your comment - Share Knowledge and Experience


 

 
Latest placement tests
Latest links
 
 
Home | Want a Job? Submit Key Skills | Employer login | My key skills | About us | Sitemap | Contact us