If anybody searching for python interview questions for freshers then this is the page we can provide all type selective questions. Top 30 questions here cited with real-time examples. So just review before going for python face to face interview.
What is the difference between Java and Python?
- It is faster than java in terms of performance.
- Dynamically typed
- Not compatible with any platform.
- Database access is weaker than java
- Indentation does by only new line.
- It is a bit slower than Python in performance-wise.
- Static typed
- Compatible to all Platform.
- Database access is Good in Java.
- Indentation does by braces.
What is the difference between list and tuples in Python?
- Lists are mutable
- List can be edited
- Syntax of the list is shown by  bracket.
- Syntax: list_1 = [5, ‘Kumar’, 20]
- Tuples are immutable
- Tuples are a list but then can’t be edited
- Syntax of tuples is shown by parenthesis.
- Syntax: tup_1 = (5, ‘Kumar’ , 20)
Write Python logic to count the number of capital letters in a file.
>>> import os
>>> with open('myfilename.txt') as myfile:
for i in myfile.read():
How to make Indentation in Python
Unlike language like C, C++, Java It has some different Indentation mechanism.
Other languages follow the indentation like braces or semicolon, where are Python followed by the new line. In order to code readable Programmer must have to make Indentation.
The syntax for example of Indentations
if salary >= 5000:
print('your are getting salary of more than 5k')
What is the difference between .py and .pyc files?
Python compiles the .py and saves files as .pyc
In Simple we can say .py files are Python source files. where as .pyc files are the compiled bytecode.
Once the *.pyc file is generated, there is no need of *.py file, unless until you edit the .py file. So it will save your time, No need to compile again an again.
What is the difference between *var and ** var in Python?
Both *var and ** var allow you a pass a variable to the number of argument to functions.
Here *var or **var you can change like anything. eg- *kar, **kar (take for your convenience)
*var is used to send a non-keyworded variable-length argument list to the function.
# Python program to illustrate
def singleStar(arg1, *var):
print "first argument :", arg1
for arg in var:
print "Next argument through *var :", arg
singleStar('Hello', 'Welcome', 'to', 'interview-questions-answers')
**var allows you to pass a keyworded variable length of arguments to a function.
if var is not None:
for key, value in var.iteritems():
print "%s == %s" %(key, value)
What are the Python Web Frameworks for developing web applications?
There are some web frameworks provided by Python. They follow below
TurboGears – It permits you to quickly develop protractile data-driven Web applications.
Bottle – It is a micro-framework for developing the web application.
web2py – it is the simplest of all the web frameworks used for developing web applications.
cherryPy – it is a Python-based Object based Web framework.
Flask – it is a micro-framework for developing and designing web applications.
Sanic– It is a Python web framework built on uvloop (event loop) which is made for fast HTTP responses.
Explain Some in-built functions to manipulate list in Python!
Compares elements of both lists – cmp(list1, list2)
Get the length of the list – len(list)
Get the max value from a list – max(list)
Get the min value from a list –min(list)
Get the lowest index in the list that object appears – list.index(obj)
Inserts object obj into list at offset index –list.insert(index, obj)
Removes and returns last object or obj from list – list.pop(obj=list[-1])
Removes object obj from list- list.remove(obj)
Reverses objects of list in place- list.reverse()
Sorts objects of list, use compare func if given – list.sort([func])
What is the usage of help() and dir() function in Python?
help() is a useful default function in Python program that can be used to get the documentation of a particular object, method, attributes, etc.
some_list = 
In Python to get all the attributes list we you have to use dir() function, where you need to pass the argument as an object. If you won’t passes any argument then it will return list of a current local namespace.
your_list = 
OutPut : You will get all default local names space like [‘__add__’, ‘__class__’,…]
What are uses of “/” and “//” operator in python?
Division(“/”): Divides left hand operand by right hand operand.
Here This work like general mathematics way. suppose
<span class="lit">7</span><span class="pun">/</span><span class="lit">2</span> <span class="pun">=</span> <span class="lit">3.5</span>
<span class="typ">In</span><span class="pln"> general way</span><span class="pun">:</span><span class="pln">
x</span><span class="pun">/</span><span class="pln">y</span><span class="pun">=</span> <span class="kwd">float</span><span class="pun">(</span><span class="pln">x</span><span class="pun">/</span><span class="pln">y</span><span class="pun">)</span>
Floor Division(“//”): The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity).
-11//3 = -4
x // y == math.floor(x/y)
What is a dictionary in Python?
In Python Dictionary defines one-to-one relationship between keys and values. Dictionaries contain a pair of keys and their corresponding values. Dictionaries are indexed by keys like JSON data or associative array.Let’s have a simple example for the sake of understanding.
Differentiate between append() and extend() methods in Python ?
append() and extend() methods are the methods of list in Python. These methods are used to a dd the elements at the end of the list.
append(element) – adds the given element at the end of the list.
extend(another-list) – adds the elements of another-list at the end of the list.
What is a monkey patch?
In Simple you can say, monkey patching is changes can done to a module or a class while the program is running.
datetime.datetime.now = lambda: datetime.datetime(2012, 12, 12)
What is lambda in python and how it used?
In Python functions are defined by using def keyword before function name, If the function having no name means anonymous function then python used lambda before it.
add = lambda a, b: a + b
What is docstring in Python?
docstrings provide a way of associating documentation with Python functions, classes, methods and modules.
It Unlike commenting in Source Code other languages C, C++, JAVA, PHP etc. The docstring line should begin with a capital letter and end with a period.
"""The class's docstring"""
"""The method's docstring"""
"""The function's docstring"""
What is TkInter?
TkInter is a toolkit for GUI development. It provides support for various controls for GUI tools such as text boxes, radio buttons, labels, buttons etc. The common attributes of them include Colors, Fonts, Cursors, Dimensions etc.
What are list of database access by python?
Python Database API supports Wide range of database server
- Microsoft SQL Server 2000
How Could you send an Email Using Python program?
Generally, SMTP is controlled by sending e-mail and routing e-mail between mail servers in other languages.But here Python provides smtplib module, which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon.
sender = 'firstname.lastname@example.org'
receivers = ['email@example.com']
message = """From: From Person <firstname.lastname@example.org>
To: To Person <email@example.com>
Subject: test email
This is a test e-mail message.
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Email has sent successfully"
print "Error:Send email Failed"
What is Pickling in Python?
Pickling is alternatively called as serialization. It serializes Python object to byte stream stored in a file format. Again byte stream can be converted to object by unpickling.
How many types of sequences are supported by Python?
Python supports 7 sequence types. They are like unicode, xrange, str, list, tuple, byte array and buffer. where xrange is deprecated in python 3.5.X.