Here you can find Python Interview Questions and Answers.
In this Python Interview Questions and Answers section you can learn and practice Python Interview Questions and Answers to improve your skills in order to face technical inerview by IT companies. By Practicing these interview questions, you can easily crack any Python interview.
AllIndiaExams provides you lots Python Interview Questions and Answers with proper explanation. Fully solved examples with detailed answer description. All students, freshers can download Python Interview Questions and Answers as PDF files and eBooks.
You no need to worry, we have given lots of Python Interview Questions and Answers and also we have provided lots of FAQ's to quickly answer the questions in the Python technical interview.
Python is simple and easy to learn language compared to other programming languages. Python was introduced to the world in the year 1991 by Guido van Rossum. It is a dynamic object oriented language used for developing software. It supports various programming languages and have a massive library support for many other languages. It is a modern powerful interpreted language with objects, modules, threads, exceptions, and automatic memory managements. Salient features of Python are Simple & Easy: Python is simple language & easy to learn. Free/open source: it means everybody can use python without purchasing license. High level language: when coding in Python one need not worry about low-level details. Portable: Python codes are Machine & platform independent. Extensible: Python program supports usage of C/ C++ codes. Embeddable Language: Python code can be embedded within C/C++ codes & can be used a scripting language. Standard Library: Python standard library contains prewritten tools for programming. Build-in Data Structure: contains lots of data structure like lists, numbers & dictionaries.
Define a method in Python?
'self' is a conventional name of method’s first argument. A method which is defined as meth(self, x ,y ,z) is called as a.meth(x, y, z) for an instance of a class in which definition occurs and is called as meth(a, x ,y, z).
Describe python usage in web programming?
Python is used perfectly for web programming and have many special features to make it easy to use. Web frame works, content management systems, WebServers, CGI scripts, Webclient programming, Webservices, etc are the features supported by python. Python language is used to create various high end applications because of its flexibility.
Is there any tool used to find bugs or carrying out static analysis?
Yes. PyChecker is the static analysis tool used in python to find bugs in source code, warns about code style and complexity etc. Pylint is a tool that verifies whether a module satisfies standards of coding and makes it possible to add custom feature and write plug-ins.
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. If all global references require global then you will be using global at anytime. You’d declare as global each reference to built-in function or to component of module which is imported. The usefulness of global declaration in identifying side-effects is defeated by this clutter.
How to find methods or attributes of an object?
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. Following code snippet shows dir() at work : class Employee: def __init__(self,name,empCode,pay): self.name=name self.empCode=empCode self.pay=pay print("dir() listing all the Methods & attributes of class Employee") print dir(e) Output dir() listing all the Methods & attributes of class Employee [ '__init__', 'empCode', 'name', 'pay']
Is there any equivalent to scanf() or sscanf()?
No. Usually, the easy way to divide line into whitespace-delimited words for simple input parsing use split() method of string objects. Then, decimal strings are converted to numeric values using float() or int(). An optional “sep” parameter is supported by split() which is useful if something is used in the place of whitespace as separator. For complex input parsing, regular expressions are powerful then sscanf() of C and perfectly suits for the task.
Class is a specific object type created when class statement is executed. To create instances objects, class objects can be used as templates which represent both code and data specific to datatype. In general, a class is based on one or many classes known as base classes. It inherits methods and attributes of base classes. An object model is now permitted to redefine successively using inheritance. Basic accessor methods are provided by generic Mailbox for subclasses and mailbox like MaildirMailbox, MboxMailbox, OutlookMailbox which handle many specific formats of mailbox.
How to prevent blocking in content() method of socket?
Commonly, select module is used to help asynchronous I/O.
In python, are there any databases to DB packages?
Yes. Bsddb package is present in Python 2.3 which offers an interface to BerkeleyDatabase library. It Interface to hashes based on disk such as GDBM and DBM are included in standard python.