Special Offer - Enroll Now and Get 2 Course at ₹25000/- Only Explore Now!

All Courses
Python Interview Questions and Answers

Python Interview Questions and Answers

October 30th, 2018

Python Interview Questions and Answers

In case you’re searching for Python Interview Questions and answers for Experienced or Freshers, you are at the correct place. Python Interview Questions and Answers provided over here will familiarize you to the maximum frequently posted questions in interviews. The question lists provided are prepared by experts in a well-organized manner which will easily boost you for the interview preparation. To land in your dream company and high paid jobs, Python course will help you to get more knowledge on Python Syntax, Functions, Multithreading, Data Types, OOPs concepts, Loops, File input and output concepts, and many more. The need of Python is increasing day by day and hence the questions are designed to fulfill the need of many professional roles like Research Analyst, Data Analyst, CRM Analyst, Data Scientist, Business Intelligence Analyst, Web Analyst and Data Science Consultant.
There is parcel of chances from many presumed organizations on the planet. The Python advertise is relied upon to develop to more than $5 billion by 2021, from just $180 million, as per Python industry gauges. In this way, despite everything you have the chance to push forward in your vocation in Python Development. Gangboard offers Advanced Python Interview Questions and answers that assist you in splitting your Python interview and procure dream vocation as Python Developer.

Best Python Interview Questions and Answers

Do you believe that you have the right stuff to be a section in the advancement of future Python, the GangBoard is here to control you to sustain your vocation. Various fortune 1000 organizations around the world are utilizing the innovation of Python to meet the necessities of their customers. Python is being utilized as a part of numerous businesses. To have a great development in Python work, our page furnishes you with nitty-gritty data as Python prospective employee meeting questions and answers. Python Interview Questions and answers are prepared by 10+ years experienced industry experts. Python Interview Questions and answers are very useful to the Fresher or Experienced person who is looking for the new challenging job from the reputed company. Our Python Questions and answers are very simple and have more examples for your better understanding.
By this Python Interview Questions and answers, many students are got placed in many reputed companies with high package salary. So utilize our Python Interview Questions and answers to grow in your career.

Q1) What does the <yield> keyword do in python?

The yield keyword can turn ant function into a generator. It works like a standard return keyword. But it will always return a generator object. A function can have multiple calls the <yield> keyword.
def testgen(index):
weekdays = [‘sun’,’mon’,’tue’,’wed’,’thu’,’fri’,’sat’] yield weekdays[index] yield weekdays[index+1] day = testgen(0)
print next(day), next(day)
Sun mon

Q2) What are the different ways to create an empty NumPy array in python?

There are two methods we can apply to create empty NumPy arrays.
The first method.
import numpy
The second method.
# Make an empty NumPy array

Q3) Can’t concat bytes to str?

This is providing to be a rough transition to python on here
f = open( ‘myfile’, ‘a+’ )
f.write(‘test string’ + ‘\n’)
key = “pass:hello”
plaintext = subprocess.check_output([‘openssl’,’aes-128-cbc’,’-d’, ‘-in’,test,’-base64′,’-pass’, key])
print (plaintext)
f.write (plaintext + ‘\n’)
The output file looks like:
test string

Q4) Expline different way to trigger/ raise exception in your python script?

Raise used to manually raise an exception general-form: raise exception-name (“message to be conveyed”).
voting_age = 15
if voting_age < 19: raise ValueError(“voting age should be at least 19 and above”)
ValueError: voting age should be at least 19 and above 2.assert statements are used to tell your program to test that condition attached to assert keyword, and trigger an exception whenever the condition becomes false. Eg: a = -10
assert a > 0 #to raise an exception whenever a is a negative number
Another way of raising an exception can be done by making a programming mistake, but that is not usually a good way of triggering an exception

Q5) Why is not__getattr__invoked when attr==’__str__’?

The base class object already implements a default __str__ method, and __getattr__function is  called for missing attributes. The example as it we must use the __getattribute__ method instead, but beware of the dangers.
class GetAttr(object):
def __getattribute__(self, attr):
print(‘getattr: ‘ + attr)
if attr == ‘__str__’:
return lambda: ‘[Getattr str]’
return lambda *args: None
A better and more readable solution to simply override the __str__ method explicitly.
class GetAttr(object):
def __getattr__(self, attr):
print(‘getattr: ‘ + attr)
return lambda *args: None
def __str__(self):
return ‘[Getattr str]’

Q6)What do you mean by list comprehension?

The process of creating a list performing some operation on the data so that can be accessed using an iterator is referred to as list comprehension.
[ord (j) for j in string.ascii_uppercase] Output:

Q7) What will be the output of the code:def foo (i=[])?

i.append (1)
return i
>>> foo ()
>>> foo ()
[1] [1,1] The argument to the function foo is evaluated once when the function is defined
However since it is a list on every all the list is modified by appending a 1 to it.

Q8) How to Tic tac toe computer move?

Below The code of computer move in the game tic tac toe in python
def computermove(board,computer,human):
for movecom in legalmoves(board):
if winner(board)==computer:
return movecom
for movecom in legalmoves(board):
if winner(board)==human:
return movecom
while rmoves not in legalmoves(board):
return rmoves

Q9) Explain about ODBC and python?

ODBC (Open Database Connectivity) API standard allows the connections with any database that supports the interface such as the PostgreSQL database or Microsoft access in a transparent manner
Three types of ODBC modules for python:
PythonWin ODBC module – limited development
mxODBC – a commercial product
pyodbc – This is open source python package

Q10) How to implement the decorator function, using dollar ()?


def dollar(fn):
def new(*args):
return ‘$’ + str(fn(*args))
return new
def price(amount, tax_rate):
return amount + amount*tax_rate
print price(100,0.1)



Q11) How to count the number of instance?

You have a class A, you want to count the number of A instance.
Hint: use staticmethod
class A:
total = 0
def __init__(self, name):
self.name = name
A.total += 1
def status():
print “Number of instance (A) : “, A.total
status = staticmethod(status)
a1 = A(“A1”)
a2 = A(“A2”)
a3 = A(“A3”)
a4 = A(“A4”)


The number of instance (A) : 4

Q12) What are the Arithmetic Operators that Python supports?

‘+’     : Addition
‘-’     : Subtraction
‘*’    : Multiplication
‘/’: Division
‘%’: Modulo division
‘**’: Power Of
‘//’: floor div
Python does not support unary operators like ++ or – operators. Python supports “Augmented Assignment Operators”. i.e.,
A += 10 Means A = A+10
B -= 10 Means B = B-10

Q13) How do you reload a Python module?

All that needs to be a module object to the imp.reload() function or just reload() in Python 2.x, and the module will be reloaded from its source file. Any other code references symbols exported by the reloaded module, they still are bound to the original code.

Q14) How does Python handle Compile-time and Run-time code checking?

Python supports compile-time code checking up to some extent. Most checks for variable data types will be postponed until run-time code checking. When an undefined custom function is used, it will move forward with compile-time checking. During runtime, Python raises exceptions against errors.

Q15) What are Supporting Python packages for data science operations?

Pandas: A package providing flexible data structures to work with relational or labeled data.
NumPy: A package that allows working with numerical based data structures like arrays and tensors.
Matplotlib: A 2D rendering engine written for Python.
Tensorflow: A package used for constructing computational graphs.

Q16) What are the ones that can be used with pandas?

A python dict, ndarray or scalar values can be used with Pandas. The passed index is a list of axis labels.

17) How To Add an Index, Row or Column to a Pandas DataFrame?

The index can be added by calling set_index() on programmer DataFrame.
For accessing rows, loc works on labels of programme index, iloc works on the positions in programme index, it is a more complex case: when the index is integer-based, programmer passes a label to ix[index].

Q18) How To Create an Empty DataFrame?

The function that programmer will use is the Pandas Dataframe() function: it requires the programmer to pass the data that programmer wants to put in, the indices and the columns.

Q19) Does Pandas Recognize Dates When Importing Data?

Yes. but programmer needs to help it a tiny bit: add the argument parse_dates when programmer by reading in data from, let is say, a comma-separated value (CSV) file.

Q20) How to convert a NumPy array to a Python List?

Use tolist():
import numpy as np
>>> np.array([[1,2,3],[4,5,6]]).tolist()
[[1, 1, 1], [2, 2, 2]]

Q21) How to set the figure title and axes labels font size in Matplotlib?

Functions dealing with text like label, title, etc. accept parameters same as matplotlib.text.Text. For the font size you can use size/fontsize:

Q22) x = [‘android’, ‘basket’, ‘cat’, ‘doctor’, ‘element’, ‘forest’, ‘gun’]

  1. What is x[-1]
  2. ‘gun’
  3. What is x[3:-3]
  4. [‘doctor’]

Q23) x = (‘animal’, 1, ‘boost’, 4)

  1. what is type(x)?
  2. tuple
  3. How can you add elements to x?
  4. A tuple is an immutable object so adding is not possible

Q24) x = [1,2,1,3,4,8,2,4,5]

  1. How can you sort the elements in x?
  2. X.sort()
  3. How can you print only unique elements in x?
  4. List(set(x))

Q25) x = {‘car’:[‘bmw’, ‘audi’], ‘bikes’:[‘hero’, ‘honda’]}

  1. How can you read each element of x?
  2. for k, v in x.items():

for an item in v:

  1. How can you add a key to x?
  2. X[‘cycle’] = ‘bsa’
  3. How can you add benefits to bikes?
  4. X[‘bikes’] = ‘beneli’

Q26) X = [1,2,3,4,5]

for elements in x:
print elements
Which of the following is correct:

  1. x is a string
  2. x is an integer
  3. x is a list
  4. x is a tuple

Ans: x is a list

Q27) To open a file “c:\scores.txt” for writing, we are using

a) outfile = open(“c:\scores.txt”, “r”)
b) outfile = open(file = “c:\scores.txt”, “r”)
c) outfile = open(“c:\\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “o”)
Ans: c

Q28) When will the else part of “try-except-else” be executed?

a) always
b) when no exception occurs
c) when an exception occurs
d) when an exception occurs to except block
Ans: b

Q29) What is the output of −

33 == 33.0
A – False
B – True
C – 33
D – None of the above
Ans: B

Q30) What is the output of following the code –

x = 2
y = 10
x * = y * x + 1
A – 42
B – 41
C – 40
D – 39
Ans: A

Q31) How can we generate random numbers in python using methods?

A – random.uniform ()
B – random.randint()
C – random.random()
D – All of the above
Ans: C

Q32) What is output for − max(”please help ”)

A – s
B – a blank space character
C – e
D – p
Ans: A

Q33) What is the output of the following code?

eval(”1 + 3 * 2”)
A – ‘1+6’
B – ‘4*2’
C – ‘1+3*2’
D – 7
Ans: D

Q34) What is the out of the code?

def rev_func(x,length):
print(x[length-1],end=” ”)
x=[11, 12, 13, 14, 15] rev_func(x,5)
A – The program runs fine without error.
B – Program displays 15 14 13 12 11.
C – Program displays 11 12 13 14 15.
D – Program displays 15 14 13 12 11 and then raises an index out of range exception.
Ans: D

Q35) Select the correct code to create a check button under parent frame1 and it should be bind to v1?

A – CheckButton(frame1, text=”Bold” , command=CheckButton)
B – Checkbutton(frame1 , text=”Bold’’ ,variable=v1 ,command=processCheckbutton)
C – Checkbutton(frame1,text=”Bold”,variable=v1.set(),command=v1.set(processCheckbut ton)
D – Checkbutton(frame.set(f1) ,text.set(”bold”) ,command=v1.set(processCheckbutton)
Ans: B

Q36) You are using a grid manager then which option is best suitable to place a component in multiple rows and columns?

A –  Only row
B – Columnspan and rowspan
C – Only column
D – Only rowspan
Ans: B

Q37) Which can be an Identifier among them in Python?

A – 1abc
B – $12a
C – _xy1
D – @python
Ans: C

Q38) What will be the output of the following code?

def total(initial = 5, *num, **key):
count = initial
for n in num:
for k in key:
count+=key[k] return count
print(total(100,2,3, clouds=50, stars=100))
A – 260
B – 160
C – 155
D – 255
Ans: D

Q39) What is dictionary in Python?

The built-in datatypes in Python are called a dictionary. It defines one-to-one Relationship between keys and values. It contains a pair of keys and their corresponding values. Dictionaries are indexed by keys. It is a collection which is unordered, changeable and indexed.
Let’s take an example:   The following example contains some keys. State, Capital,Language. Their corresponding values are Karnataka, Bangalore, and Kannada respectively.
Dict={ ‘Country’:’Karnataka’,’Capital’:’Bangalore’,’Launguage’:’Kannada’}
print dict[Country] Karnataka
Print dict[Capital] Bangalore
Print dict[Launguage] Kannada

Q40) How memory is managed in Python?

Python private heap space manages python memory. Python heap has all Python objects and data structures. Access to this private heap is restricted to programmer also Python private heap is taken care by the interpreter.
The core API gives access to some tools for the programmer to code. Python memory manager allocates python heap space.

Q41)What is the output of this following statement?

for i in range(5);
with open(“data.txt”, ”w”) as f:
if I>1:
print f.closed

  1. A) True B) False C) None     D) Error

Ans: A

Q42) Write a coding in Find a Largest Among three numbers?

num1 = 10
num2 = 14
num3 = 12
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
largest = num3
print(“The largest number between”,num1,”,”,num2,”and”,num3,”is”,largest)
The largest Number is 14.0

Q43) What is Lambda in Python?

lambda is an one line anonymous function,
Sum=lambda i,c:i+c

Q44) What is the difference between list and tuples?

  • Lists are the mutable elements where we can able to perform the task in the existed variable. Lists can able to reduce the utilization of memory
  • Tuples are immutable so it can execute faster when compared with list. But it will wastes the memory.

Q45) What are the key features of Python?

The python doesn’t have any header files

  • It doesn’t have any structure or syntax except the indentation.
  • It can execute the instructions fastly because of the RISC architecture.
  • It consumes only less memory because of no internal executions.
  • It doesn’t have any compilers compilation can be done at the time of the program.

Q46) How to delete a file in Python?

In Python, Delete a file using this command,
os.remove (filename)

Q47) What is the usage of help() and dir() function in Python?

Help() and dir() both functions are accessible from the Python interpreter used for viewing a consolidated dump of built-in functions. Help() function: The help() function is used to display the documentation string and also facilitates you to see the help related to modules, keywords, attributes, etc.

Q48) Which of the following statements create a dictionary? (Multiple Correct Answers Possible)

a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) d = (40:”john”, 45:”50”)
Ans: All of the above

Q49) Which of the following is an invalid statement?

a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
Ans: c

Q50) What is the output of the following?

if ‘1’ != 1:
raise “someError”
print(“someError has not occured”)
except “someError”:
print (“someError has occured”)

  1. a) someError has occured
    b) someError has not occured
    c) invalid code
    d) none of the above

Ans: b

Q51) What is the maximum possible length of an identifier?

a) 31 characters
b) 63 characters
c) 79 characters
d) None of the above
Ans: d

Q52) Differentiate list and tuple with an example?

difference is that a list is mutable, but a tuple is immutable.
>>> mylist=[1,3,3] >>> mylist[1]=2
>>> mytuple=(1,3,3)
>>> mytuple[1]=2
TypeError: ‘tuple’ object does not support item assignment

Q53) Which operator will be helpful for decision making statements?

comparison operator

Q54) Out of two options which is the template by default flask is following?

a) Werkzeug
b) Jinja2
Ans : b

Q55) Point out the use of help() function

Help on function copy in module copy:
Shallow copy operation on arbitrary Python objects.

Q56) From below select which data structure is having key-value pair ?

Ans : c

Q57) Differentiate *args and **kwargs?

*args :
We can pass multiple arguments we want like list or tuples of data
**kwargs :
we can pass multiple arguments using keywords

Q58) Use of Negative indices?

It helps to  slice from the back
mylist=[0,1,2,3,4,5,6,7,8] >>>mylist[-3] 6

Q59) Give an example for join() and split() funcitons

>>> ‘,’.join(‘12345’)
>>> ‘1,2,3,4,5’.split(‘,’)
[‘1’, ‘2’, ‘3’, ‘4’, ‘5’]

Q60) Python is case sensitive ?

Ans : a

Q61) List out loop breaking functions

  1. break
  2. continue
  3. pass

Q62) what is the syntax for exponentiation and give example?

2**3 = 8

Q63) Which operator helps to do addition operations ?

arithmetic operator

Q64) How to get all keys from dictionary ?


Q65) Give one example for multiple statements in single statement?


Q66) What is the output for the following code?

>> def expandlist(val, list=[]):
return list
>>> list1 = expandlist (10)
>>> list2 = expandlist (123,[])
>>> list3 = expandlist (‘a’)
>>> list1,list2,list3
Ans : ([10, ‘a’], [123], [10, ‘a’])

Q67) Number of argument’s that range() function can take ?

a. 3
b. 5
Ans : a

Q68) Give an example to capital first letter of a string?

print a[0].upper()

Q69) How to find whether string is alphanumeric or not?

str = “hjsh#”;
print str.isalnum()
Ans :False

Q70) Which method will be used to delete a file ?


Q71) What is difference between match & search in regex module in python?

Match Checks for a match only at the beginning of the string, while search checks for a match anywhere in the string.

Q72) Can we change tuple values? If yes, give an example.

Since tuple are immutable, so we cannot change tuple value in its original form but we can convert it into list for changing its values and then convert again to tuple.
Below is the example:

Q73) What is purpose of __init__ in Class ? Is it necessary to use __init__  while creating a class ?

__init__ is a class contructor in python.  __init__  is called when we create an object for a class and it is used to initialize the attribute of that class.
eg :  def __init__ (self, name ,branch , year)
self.name= name
self.branch = branch
self.year =year
print(“a new student”)
No, It is not necessary to include __init__ as your first function every time in class.

Q74) Can Dictionary have a duplicate keys  ?

Python Doesn’t allow duplicate key  however if a key is duplicated the second key-value pair will overwrite the first as a dictionary can only have one value per key.
For eg :
>>> my_dict={‘a’:1 ,’b’ :2 ,’b’:3}
>>> print(my_dict)
{‘a’: 1, ‘b’: 3}

Q75) What happened if we call a key that is not present in dictionary and how to tackle that kind of error ?

It will return a Key Error . We can use get method to avoid such condition. This method returns the value for the given key, if it is present in the dictionary and if it is not present  it will return None (if get() is used with only one argument).
Dict.get(key, default=None)

Q76) What is difference b/w range and arange function in python?

numpy.arange :  Return evenly spaced values within a given interval. Values are generated within the half-open interval [start, stop) .the interval including start but excluding stop. It return an Array .
numpy.arange([start, ]stop, [step, ]dtype=None)
Range : The range function returns a list of numbers between the two arguments (or one) you pass it.

Q77) What is difference b/w panda series and dictionary in python?

Dictionaries are python’s default data structures which allow you to store key: value pairs and it offers some built-in methods to manipulate your data.

Q78) Why it need to be create a virtual environment before staring an project in Django ?

A Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects.
Benefit of creating virtualenv :
We can create multiple virtualenv , so that every project have a different set of packages .
For eg. if one project we run on two different version of Django , virtualenv can keep thos projects fully separate to satisfy both requirements at once.It makes easy for us to release our project with its own dependent modules.

Q79) How to write a text from from another text file in python ?

Below is the code for the same.
import os
file = open(‘input.txt’ ,’w’)
with open(“output.txt”, “w”) as fw, open(“input.txt”,”r”) as fr:

Q80) what is difference between input and raw_input?

There is no raw_input() in python 3.x  only input() exists. Actually, the old raw_input() has been renamed to input(), and the old input() is gone, but can easily be simulated by using eval(input()). In python 3.x  We  can  manually compile and then eval for getting old functionality.

python2.x python3.x
raw_input() input()
input() eval(input())

Q81) What are all important modules in python  required for a Data Science ?

Below are important module for a Data Science :

  • NumPy
  • SciPy
  • Pandas
  • Matplotlib
  • Seaborn
  • Bokeh
  • Plotly
  • SciKit-Learn
  • Theano
  • TensorFlow


Q82) What is use of list comprehension ?

List comprehensions is used to transform one list into another list. During this process, list items are  conditionally included in the new list and each items are transformed as required. Eg.
my_list=[] my_list1=[2,3,4,5] Using  “for “ loop :
for i in my_list1:
Using List comprehension :
my_list2=[i*2 for i in my_list1] print(my_list2)

Q83) What is lambda function ?

lambda function is used for creating small, one-time and anonymous function objects in Python.

Q84) what is use of set in python?

A set is a  type of python data Structure which is unordered and unindexed. It  is declared in curly braces . sets are used when you required only unique elements .my_set={ a ,b ,c,d}

Q85) Does python has private keyword in python ? how to make any variable private in python ?

It does not have private keyword in python and for any instance variable to make it private you can __  prefix in the  variable so that it will not be visible to the code outside of the class .
Eg .  Class A:
def __init__(self):
def printNum(self):
print self.__num

Q86) What is pip and when it is used ?

it is a  package management system and it is used to install many python package. Eg. Django , mysql.connector
Syntax : pip install packagename
pip install Django : to install Django module

Q87) What is head and tail method for Data frames in pandas ?

Ans : Head : it will give the first N rows of Dataframe.
Tail : it will give last N rows of Dataframe.
By default it is 5.

Q88) How to change a string in list ?

we can use split method to change an existing string into list.
s= ‘Hello sam good morning ’
[‘hello’ , ‘sam’ , ‘good’ , ‘morning’]

Q89) How to take hello as output from below nested list using indexing concepting in python.

my_list=[1,2,3,[5,6,7, [2,7,[‘hello’], 4,5]],3,4] Ans : my_list[3][3][2][0] print(my_list)

Q90) What is list when we have to use ?

Lists always store homogeneous elements.  we have to use the lists when the data is same type and when accessing is more insteading of inserting  in memory.

Q91) What is dict when we have to use ?

Dict is used to store key value pairs and key is calculated using hash key. This is used when we want to access data in O(1) time as big O notation in average case. Dict I used in u can say super market to know the price of corresponding while doing billing

Q92) What is tuple when we have to use ?

Tuple is hetrogenous and we have to use when data is different types.

Q93) Is String Immutable ?

Yes because it creates object in memory so if you want to change through indexing it will throw an exception since it can’t be changes I,e immutable.

Q94) How to handle Exception ?

We can handle exceptions by using try catch block . we can also else block in python to make it executed based on condition.

Q95) Will python work multiple inheritance?

Yes it works .by sequentially referring parent class one by one.

Q96) Will class members accessible by instances of class?

Yes by referring corresponding attributes we can access.

Q97) What are Special methods in python and how to implement?

Special methods in python are __init__,__str__,__iter__,__del__
__init__-it will initialize when class loads.
__str__-It is used to represent object in a string format.
__iter__-it I used to define iteration based on requirements.
__del__-It is used to destroy object when it is not required  for memory optimization.

Q98) How to handle deadlock in python.

By providing synchronization methods so that each thread access one at a time.It will lock another thread until thread fine it execution.

Q99) How for loop will works in python?

For loop internally calls iter method of an object for each call.

Q100) What is List comprehension how to define it  and when to use?

List Comprehensions are expression based iteration.
So we have to give expression and then provide loop and provide if condition if needed.
We have to use when we want to define in such a way that write the code in a compact way.

Q101) What is set when we have to use?

Set is used to define unique elements without duplicates.  So if you have lump of data and we are searching through email record. By using set we can get the unique elements.

Q102) How django works ?

Django will take an url from frontend and look for url reolvers and url will ap corresponding view and if data to be handled it will use certain model to make any database transactions and give repone via view and then passs to UI.
Or django template

Q103) Is python pure object oriented programming ?

Yes in python all types are stored a objects.

Q104) What are packages in python which are  commonly used explain one ?

The packages used are os, sys,time,tempfile,pdb,
Os –it is used for file and directories handling.
Pdb-It is used to debug the code to find the root cause of issue.

Q105) How will you merge 2 dictionaries in python?

a = {1:’1’} , b={2:’2’}
c= {**a,**b}

Q106) What is the other way of checking truthiness?

These only test for truthiness:
if x or y or z:
if any((x, y, z)):

Q107) How will you verify different flags at once?

flags at once in Python
v1,v2,v3 = 0, 1, 0
if v1 == 1 or v2 == 1 or v3 == 1:
if 1 in (v1, v2, v3):

Q108) What happens when you execute python == PYTHON?

You get a Name Error Execution

Q109) Tool used to check python code standards?


Q110) How strings can be sliced?

They can be generally treated as arrays without commas.
Eg: a =  “python”
a[i] -> i can be any number within the length of the string

Q111) How to pass indefinite number of arguments to any function?

We use **args when we don’t know the number of arguments to be passed

Q112) In OOPS what is a diamond problem in inheritance?

During multiple inheritance, when class X has two subclasses Y and Z, and a class D has two super classes Y and Z.If a method present in X is overridden by both Y and Z but not by D then from which class D will inherit that method Y or Z.

Q113) Among LISTS,SETS,TUPLES which is faster?


Q114) How Type casting is done in python?

(Str -> int)
s = “1234” # s is string
i = int(s) # string converted to int

Q115) How python maintains conditional blocks?

Python used indentation to differentiate and maintain blocks of code

Q116) Write a small code to explain repr() in python ?

Repr gives the format that can be read by the compiler.
print ” y :”,y
print “str(y) :”,x
print “repr(y):”,z
y : 2333.3
str(y) : 2333.3
repr(y) : 2333.3000000000002

Q117) How to encrypt a string?

str_enc = str.encode(‘base64’, ‘strict’)

Q118) Functions are objects -> Explain ?

# can be treated as objects
def print_new(val):
return val.upper()
print ( print_new(‘Hello’))
yell = print_new
print yell(‘different string’)

Q119) Explain the synbtax to split a string in python?


Q120) How can you identify the data type of any variable in python?

Use type(var)

Q121) What does MAP function in python do?

map()  returns a list of the results after it applys the function to each item in a iterable data type (list, tuple etc.)

Q122) What does the enum function in python do?

When we need to print the vars index along when you iterate, we use the enum function to serve this purpose.

Q123) Explain assert in action?

assert “py” == “PY”, “Strings are not equal”

Q124) How does pop function works in set data types?

Pop deletes a random element from the set

Q125) Is Python open source? If so, why it is called so?

Python is an open source programming language. Because Python’s source code (the code in which Python software is written) is open for all and anyone can have a look at the source code and edit.

Q126). Why Python is called portable?

Because we can run Python in wide range of hardware platforms and has similar interfaces across all the platforms

Q127) How to give comments in Python?

Using Hashes (#) at the starting of a line

Q128) How to create prompt in the console window?

Using input function

Q129) How to write multiple statements in a single line in Python?

Using semicolon between the statements

Q130) List out standard datatypes in Python

Numbers, string, list, tuple, dictionary

Q131) Which standard datatype in Python is immutable?


Q132) What is indexing? Explain with an example

Indexing is the numbering of characters in string or items in list, tuple to give reference for them. It starts from 0. Str = “Python”. The index for P is 0, y is 1, t is 2 and goes on.

Q133).Which statement is used to take a decision based on the comparison?

IF statement

Q134)  List out atleast two loop control statements

break, continue, pass

Q135) What is the result of pow(x,y)

X raised to the power Y

Q136) What is the difference between while and for loop?

While loops till the condition fails, for loops for all the values in the list of items provided.

Q137) Which method removes leading and trailing blanks in a string?

strip – leading and trialing blanks, lstrip – leading blanks, rstrip – trailing blanks

Q138) Which method removes and returns last object of a list?


Q139) What is argument in a function?

Argument is the variable which is used inside the function. While calling the function we need to provide values to those arguments.

Q140) What is variable length argument in function?

Function having undefined no. of arguments are called variable length argument function.  While calling this function, we can provide any no. of arguments

Q141) What is namespace?

Namespace is the dictionary of key-value pairs while key is the variable name and value is the value assigned to that variable.

Q142) What is module?

Module is a file containing python code which can be re-used in a different program if it is a function.

Q143) Which is the default function in a class?

Explain about it – _init_. It is called class contructor or initialization method. Python calls _init_ whenever you create a instance for the class

Q144) What is docstring? How to define it?

docstring is nothing but a comment inside the block of codes. It should be enclosed inside “”” mark. ex: “”” This is a docstring ”””

Q145) What is the default argument in all the functions inside a class?


Q146) How to send a object and its value to the garbage collection?

del objname

Q147) How to install a package and import?

In DOS prompt, run pip install package_name and run import package_name in editor window in Python’s IDE.

Q148) Name the function which helps to change the files permission


Q149) Which is the most commonly used package for data importing and manipulation?


Q150) Will python support object oriented?

Yes, it will support by wrapping the code with objects.

Q151) IS python can be compatible with command prompt?

Yes, it can be accessed through command prompt.

Q152) How Lists is differentiated from Tuples?

List are slow, can be edited but Tuples are fast and cannot be edited.

Q153). Use of NUMPY package?

It is fastest, and the package take care of the number calculations.

Q154). Uses of python?

Pie charts, web application, data modeling, automation and Cluster data.

Q155) Does python interact with Database?

Yes, it interfaces to most of the Databases.

Q156) Is python is intended oriented?

Yes, it will throw error if it is not in sequence.

Q157) How is Garbage handled in python?

It will be automatically handle the garbage after the variable is used.

Q158) How will you check python version?

Using python –version.

 Q159) How will you quit the python?

Using exit()

Q160) Does Python has any command to create variable?

No, just (x =244)

Q161) What is complex type in python?

It is mixture of variable and number.

Q162) Casting in python?

To make String use command str(2) = ‘2’

Q163) What is strip in python?

Used to remove white spaces in String

Q164) Other String literals?

Lower, upper,  len, split, replace.

Q165) Python operators?

Arithmetic, Assignment, Comparison, Logical, Identity, Membership and Bitwise.

Q166) Membership operator in python?

In and not in.

Q167) Lambda in python?

Can take only one expression but any number of Argument.

 Q168) Dict in python?

It is something like key and value pair as Map in java.

 Q169) Does python has classes?

In python all are denoted as some classes.

Q170) Multi threading on python?

It is a package in python and it use GIL to run the thread one after the other. But isn’t it being not good to use here.

Q171) What is python private heap space?

It is a inbuild garbage collection like java and this space can be used by the developer.

Q172) Does python support inheritance?

Yes, it supports all forms of inheritance single, multiple, hierarchical and multi-level

Q173) Benefits of Flask?

It is light weight and independent package. Mainly a web micro framework.

Q174) How dir() function is used in python?

The defined symbols are defined here.

Q175) Will exit method in python de allocate the global namespace?

No, it has a specific mechanism which it follows as an individual portion.

Q176) Has python has monkey patching concept within?

Yes of course, it does dynamic transactions during the run time of the program.

Q177) args vs kwargs?

Args – don’t know how many arguments are used.
Kwargs- don’t know how many keywords are used.

Q178) use of isupper keyword in python?

This will prompt the upper keyword of any character in a string literal.

Q179) pickling vs unpickling?

If the objects translated from string then it seems to be pickling
If the String is dumped to objects then it seems to un picking

Q180) What is py checker in python?

It is tool to quantitatively detects the bugs in source code.

Q181) What are the packages?


Q182) Pass in Python?

IT is a namespace with no character and it can be moved to next object.

Q183) How is unit test done in python?

It is done in form of Unittest. This does major of testing activity.

Q184) Python documentation is called?

DoctString such as AI, Python jobs ,Machine learning and Charts.

Q185) Convert Sting to number and viceversa in python?

Str() for String to number and oct() for number to string.

Q186) Local vs Global in python?

Anything inside the function body is local and outside is global as simple as that.

Q187) How to run script in python?

Use py command or python command to run the specific file in Unix.

Q188) What is unlink in python?

This is used to remove the file from the specified path.

Q189) Program structure in python?

Always import the package and write the code without indention

Q190) Pyramid vs Django?

Both used for larger application and Django comes with a ORM framework.

Q191) Cookies in python?

Sessions are known as cookies here it is used to request from one object to other.

Q192) Different types of request in python?

Before request – it is used to passes without the arguments.
After request – it is used to pass the request and response will be generated.
Tear down request – it is used as same as past but it does not provide response always and the request cant be changed.

Q193) How is fail over mechanism works in python?

Once the server shoots the fail over term then it automatically tends to remove  the packet each on the solid base and then re shoot again on its own. Socket wont get removed or revoked from the orgin.

Q194) Dogpile mechanism explain?

Whenever the server host the service and when it gets multiple hits from the various clients then the piles get generated enormously. This effect will be seems as Dogpile effect. This can be captured by processing the one hit per time and not allowed to capture multiple times.

Q195) What is CHMOD 755 in python?

This will enhance the file to get all the privileges to read write and edit.

Q196) CGI in Python?

This server mode will enable the Content-type – text/html\r\n\r\n
This has an extension of .cgi files. This can be run through the cgi command from the cmd prompt.

Q197)  Sockets explain?

These are the terminals from the one end to the other using the  TCP, UDP protocols this requires domain, type, protocol and host address.
Server sockets such as bind, listen and accept
Client socket such as connect.

Q198) Assertions in python?

This is stated as the expression is hits when we get the statement is contradict with the existing flow. These will throw the error based on the scenario.

Q199) Exceptions in python?

This is as same as JAVA exceptions and it is denoted as the try, catch and finally this also provides the user defined expression.

Q200) What made you to choose python as a programming language?

The python programming language is easy to learn and easy to implement.
The huge 3rd party library support will make python powerful and we can easily adopt the python

Q201) what are the features of python?

  • The dynamic typing
  • Large third party library support
  • Platform independent
  • OOPs support
  • Can use python in many areas like machine learning,AI,Data science etc..

Q202) How the memory is managed in python?

The private heap space is going to take care about python memory. whenever the object is created or destroyed the heap space will take care. As a programmer we don’t need to involve in memory operations of python

Q203) What is the process of pickling and unpicling?

In python we can convert any object to a string object and we can dump using inbuilt dump().this is called pickling. The reverse process is called unpicling

Q204). What is list in python?

A list is a mutable sequential data items enclosed with in[] and elements are separated by comma.
Ex: my_list=[1,1.2,’chandra’,’Besant’,[4,5,6]] In a list we can store any kind of data and we can access them by using index

Q205) What is tuple in python?

A tuple is immutable sequential data element enclosed with in () and are separated by comma.
Ex: my_tuple=(1,4,5,’mouli’,’python’)
We use tuple to provide some security to the data like employee salaries, some confidential information

Q206) Which data type you prefer to implement when deal with sequential data?

I prefer tuple over list. Because the tuple accessing is faster than a list because its immutability

Q207) What are advantages of a tuple over a list?

We can use tuple as a dictionary key because it is hash able and tuple accessing very fast compare to a list.

Q208) What is list comprehension and dictionary comprehension and why we use it?

A list comprehension is a simple and elegant way to create a list from another list. we can pass any number of expressions in a list comprehension and it will return one value, we can also do the same process for dictionary data types
Data=[99,100,345,45,43,67,43,67] Ex: new_list = [n**2 for n in data if n%3==0]

Q209) What is the type of the given datatype a=1?

c)Invalid datatype

Q210) Which is the invalid variable assignment from the below?

b)The variable=10
d)none of the above

Q211)  Why do we use sets in python?

Generally we use sets in python to eliminate the redundant data from any data. And sets didn’t accept any mutable data types as a element of a set
Ex: my_set={123,456,’computer’,(67,’mo’)}

Q212) What are the nameless functions in python?

The anonymous functions are called nameless functions in python. We can also call it as lambda function. The lambda functions can be called as a one liner and can be created instantly
Syntax: lambda arguments: expression
Ex: hello=lambda d:d-(d+1)
To call the lambda function

Q213) What is map and filter in python?

Map and filter are called higher order functions which will take another functions as an argument.

Q214) What is the necessity to use pass statement in python program?

Pass is no operation python statement. we can use it while we are implementing the classes or functions or any logic. If class is going be define later in the development phase we can use pass statement for the class to make it syntactically make it valid.
Ex: def library():

Q215) What is *kwargs and **kwargs?

Both are used in functions. both are allowed to pass variable number of arguments to a function only difference is *kwargs is used for non-key word arguments and **kwargs is used for key word arguments
Ex: def kwargs(formal_arg, *kwargv):
print(“first normal arg:”, formal_arg)
for arg in kwargv:
print(“another arg through *argv:”, arg)
kwargs(‘mouli’, ‘ramesh’, ‘rajesh’, ‘kanna’)

Q216) Explain about negative indexing?

Negative indexing is used in python sequential datatypes like list,string,tuple etc
We can fetch the element from the back with out counting the list index
Ex: list1[-10]

Q217) What is file context manager?

To open a file in safe mode we use WITH context manager. This will ensure the file crashing from some exceptions. we don’t need to close the file explicitly
Ex: with open(‘sample.txt’,’w’) as f:

Q218) Explain between deep and shallow copy?

The deep copy , copy the object with reference so that if we made any changes on the original copy the reference copy will be effected, shallow copy ,copy the object in a separate memory so that if we do any changes on original it won’t effect the shallow copy one

Q219) How can you make modules in python?

First we need to save the file with somename.py
Second import the somename.py in the newfile.py, so that we can access the somename.py functions in the newfile.py. so that somename.py acts as a module. Even we can share our module to the rest of the
world by registering to PYPY community

Q220) Explain about default database with python?

SQLite3 comes with python3. It is light weight database for small scale of application

Q221) What are different modes in file operations?

There are 3 modes in python file operations read, write and append sometimes we can do both at a time. read(),readline(),readlines() are the inbuilt functions for reading the file write() is inbuilt function for writing to the file

Q222) What is enumerate() explain its uses?

Enumerate is a built in function to generate the index as we desired in the sequential datatypes
Ex: for c ,i in enumerate(data,p):
Here p is optional if we don’t want it we can eliminate it

Q223) Can we use else with for loop in python?

Yes we can use. once all the for loop is successfully executed the else part is going to execute, If there are any error occurs or any break happened in the loop then the else is not going to execute
Ex: for I in list1:
print(execution done)
even we can use else with while also

Q224) What is type() and id() will do?

The type() will give you the information about datatype and id() will provide you the memory location of the object

Q225) What is decorators?

The decorators are special functions which will very useful when tweaking the function or class.it will modify the functionality of another function.

Q226) Explain about different blocks in exception handling?

There are three main blocks in python exception handling
In the try block we will write all the code which can be prone to error, if any error occurred in this block it will go to the except block. If we put finally block also the execution will hit the finally block.

Q227) Explain inheritance in python?

Inheritance will allow the access to the child call meaning it can access the attributes and methods of the base. There are many types in the inheritance
Single inheritance: in this one, have only one base class and one derived class
Multilevel inheritance: there can be one or more base classes and one more derived classes to inherit
Hierarchical: can derive any number of child classes from single base class
Multiple: a single derived can be inherited from any number of base classes
29.write sorting algorithm in python for given dataset=[‘10’,’22’,’9’,’3’,’1’] using list comprehension
x=[int(i) for I in dataset] print(x.sort())

Q228) Explain about multi-threading concept in python?

Multi-threading process can be achieved through the multiprocess inbuilt module. GIL(global interpreter lock ) will take care about the multiprocessing in python. simultaneously there are several threads can be run at same time. The resource management can be handled by GIL.

Q229) Can we do pattern matching using python?

Yes, we can do it by using re module. like other programming languages python has comes with powerful pattern matching technique.

Q230) What is pandas?

Pandas is data science library which deal with large set of data. pandas define data as data frame and processes it. Pandas is a third party library which we need to install.

Q231) What is pip?

Pip is a python package installer. Whenever we need third party library like paramiko,pandas etc
We have to use pip command to install the packages
Ex: pip install paramiko

Q232) What is the incorrect declaration of a set?


Q233) What is OS module will do in python?

OS module is giving access to python program to perform operating system operations like changedirectory, delete or create.
Ex: import os

Q234) What is scheduling in threading?

Using scheduling we can decide which thread has to execute first and what is the time to execute the thread. And it is highly dynamic process

Q235) What is the difference between module and package?

A package is folder which can have multiple modules in it.
We can import module by its package name.module name

Q236) How we can send email from python?

We can use smtplib inbuilt module to define smtp client, that can be used to send email

Q237) What is TKIner?

TKIner is a python inbuilt library for developing the GUI

Q238) How can you prevent abnormal termination of a python program

We can prevent the abnormal termination by using the exception handling mechanism in python. Try , except and finally are the key words for handling the exception. we can raise our own exceptions in the python. They are called user exceptions

Q239) what module is used to execute linux commands through the python script and give us with one example

We can use OS module to execute any operation system commands. We have to import the OS module first and then give the commands
Ex: import os

Q240) what is the process to set up database in Django

First we need to edit the settings.py module to set up the database. Django comes with SQLite database by default, if we want to continue with default database we can leave settings.py as it is. If we decide to work with oracle or other kind of databases like oracle your database engine should be ‘django.db.backends.oracle’. if it is postgresql then the engine should ‘django.db.backends.postgresql_psycopg2’. We can add settings like password, name host etc.

Q241) what is Django template

A django template is a simple text file which is used to create HTML,CSV or XML. A template contains variables that is replaced with values when we evaluates it

Q242) what is the uses of middleware in Django?

Middleware is responsible for user authentication, session management .

Q243) what is Django architecture

Django architecture contains models ,views, templates and controller
The model describes the database schema and data structure. the views retrieves data from model and pass it to the template. Templates are described how the user see it. controller is the logic part and heart of the Django

Q244) List some of the data science libraries in python


Q245) How do substitute a pattern in a string using re module

Import re
>>> re.sub(‘[abc]’, ‘o’, ‘Space’)
>>> re.sub(‘[aeu]’, ‘n’, re.sub(‘[abc]’, ‘o’, ‘Space’))

Q246) What is random module will do in python and what are the functions we can apply on random module

Random module will gives the random number from the specific range. Every time we execute we will get the random number
Are some of the useful functions in random module

Q247) What are the noted modules of python in terms of networking

Paramiko, netmiko, pexpect etc
These module will create a ssh connection between server and the program

Q248) What is beautifulSoup module will do in python?

We are using the module for pulling the data from HTML and XML files

Q249) What is requests module will do?

It is a python http library. The aim of the requests module is to make http requests simpler and more human friendly
Import requests
r = requests.get(‘https://api.github.com/user’, auth=(‘user’, ‘pass’))
>>> r.headers[‘content-type’] ‘application/json; charset=utf8’
>>> r.encoding
>>> r.text # doctest: +ELLIPSIS
>>> r.json() # doctest: +ELLIPSIS
{u’private_gists’: 419, u’total_private_repos’: 77, …}

Q250) What are the basic datatypes in python?

Python datatypes include int, float, strings, lists, tuples, sets, dictionaries.

Q251) How Manages to Python Handle Memory Management?

  • Python is a separate on heaps to keep its memory. So the heap contains all the Python information and these data structures.
  • And it’s the Python created handler that manages the Individual heap.
  • Python employs a built-in garbage receiver, which salvages all the available memory including offloads it to some heap space.

Q252) What is means by string Python?

A string in Python is a mixture of the alpha-numeric volume of characters. They are clear of objects Volume. It suggests that both don’t help move once all get assigned a value. Python provides to programs of join(), replace(), or split() to alter strings variable.

Q253) What does the meaning of Slicing in python?

Python Slicing is defined as Lists of  Tuples and Arrays Volume function. The Lists element function has a default bit fo the functionality while slicing. If there is a no consequence of before that first colon, it expects to begin at the start index of the list.

Q254) Definition of %S In Python?

  • Python it has to been guide for formatting of any value into a string volume function. It may include quite complex characters.
  • It’s One of the popular usages of the start contents into a string including the %s form specifier.
  • The %S formatting helps Python in a similar variable volume syntax as the C function printf().

Q255) what does a function of python programming?

  • A function is an object which describes a block of the system and is a reusable object. It takes modularity to a performance code program and a higher level of code reusability.
  • Python has to give us several built-in functions Volume such as print() function volume and it gives the ability to perform a user-defined function.

Q256) How to write a functioning volume for python?

  • Step-1: To begin the function Volume of start writing the function with the keyword and then specify the Volume function name.
  • Step-2: We can immediately give the reasons and enclose them doing the parentheses.
  • Step-3: After pushing an enter, we can do it determine the coveted Python records for execution.

Q257) What is means by Call function in Python?

A python function value gets treated because of a callable object. It can provide any thoughts value and also pass a value or increased values into the model of a tuple. Apart from this function, Python should additional constructs, such as being groups or the class instances fit in the related category.
Q258) How to use of return keywords in python?

  • The purpose of a value function get the inputs and return value of some output.
  • The return value of is a Python statement if it’s we can relate to using for sending content following to its caller.

Q259) What is meant by“Call By Value” In Python?

  • In call-by-value, that argument to be valued expression or value becomes connected to the particular variable in this function.
  • Python command treats that variable being confined within the function-level field.
  • Any changes done to this variable will continue local and order reflect outside the function.

Q260) What does means by “Call By Reference” In Python?

The Call-by-reference we pass as an argument by reference volume, then it is possible because of an absolute source on the use, first then some simple copy. In such any case, any change to the discussion instructions further is obvious to the caller.

Q261) Difference between Pass and Continue In Python?

The continue report executes the loop value to return from the following emphasis. On the opposite, that passing record instructs to make nothing, including the remainder from the code effects as usual.

Q262) What is meant by R strip() In Python?

Python gives the r-strip() system to increases this string value function but allows avoid this whitespace symbols of that end. This r-strip() transmits that numbers value function of right end based upon particular argument value a string specifying the group of numbers to get excluded.

Q263) What does defined by whitespace in python?

Whitespace is representing the characters string value function that we practice for spacing moreover separation. They maintain the“empty” value function symbol. In Python, it could move some tab or space.

Q264) What is defined Isalpha() In Python?

Python has been provided that built-in isalpha() value function for each string manipulating purpose. It reflects the True value function if all types in this string value function are of alphabet type number, else value function it returns False.

Q265) What does making the CPython Different From Python?

Jython means an implementation from some Python programming language that can operate code using on this Java platform. Jython is quiet as compared to CPython and requires agreement with CPython libraries. A Python implementation is written in C# getting a Microsoft’s .NET framework.

Q266) Which is the package Fastest Form Of Python?

  • PyPy gives maximum agreement while utilizing CPython implementation as increasing its performance.
  • The tests verified that PyPy is almost five times faster than unique CPython.

Q267) What does the meaning of GIL In Python Language?

Python is helped to  GI(thats means by the global interpreter) which operates some mutex done to ensure introduction into Python objects, synchronizing multiple threads of running these Python bytecodes at the same time.

Q268) How do Python Thread Safe?

Python ensures the reliable path of the threads. It does this GIL mutex to secure synchronization. If a thread fails the GIL lock through any time, when you must to get this system thread-safe.

Q269) How Does determine the Python Manage The Memory?

  • Python performs a property manager within which operates any of its articles also data structures.
  • This heap manager makes that allocation/de-allocation from heap space to objects.

Q270) What is a means by “Tuple In Python”?

A tuple is a group of specific data structure under Python is immutable. They mean similar to progressions, really prefer the lists. Also, that tuples follow parentheses as including, but these programs have square sections in their syntax.

Q271) What does means by split do in Python?

This is the opposite of order which mixes or combines strings within one. To do this, you practice this split function value. What it takes is divided or develop up a string and attach that data into each order collection using a specified separator. If none separator is specified while you charge against specific function, whitespace order signify done by default.

Q272) How do you convert a string to in python?

Use the “int” String function value to convert the number to an integer value. Add five value to the integer. Then, the “str” function value it’s to converts the integer function value to a string value function that Python concatenates and print the output value of the answer.

Q273) How do you reverse any string in Python?

This is continued the reverse value function part syntax. It goes outcomes too by doing [beginvalue: and endingvalue: step] – by leaving start value and end off value and defining a step of -1, it reverses value function a string function.

Q274) What does by Python a scripting language?

Python is identified as a scripting language because it is an interpreted language also because that is simple to record scripts in it. A defined python communication programming is a language whose programs have to be obtained before they can be run.

Q275) What language is Python based on?

Since largest recent OS continue written in C, compilers/editors before improved high-level languages exist also written in C. Python continues an exception – its various popular/”traditional” implementation means described CPython more is written in C.

Q276) What is the best free website to learn Python?

Python.org. is one the best Python Software Foundation’s official website is further one of the valuable free source locations.SoloLearn- If it refers to a modular, crash-course-like information environment, SoloLearn gives an excellent, step-by-step knowledge program for beginners, TechBeamers , Hackr.io, Real Python.

Q277) Difference between Python and Java?

The Two biggest difference languages signify that the Java is one the statically typed program coding language and Python is one of the dynamical typed. Python is very heavily code programming language but dynamically typed. In certain means types in one code remain confined to strongly Copied something at runtime.

Q278) How Can you declare the variables function in Python?

In Java or C, every variable must be certified before it can be used. Declaring the variable means connecting it to a data type value function. Declaration of variables is expected in Python. You can specify an integer value function to a variable, use it is an integer value function for a while and when specifying a string to the variable function.

Q279) How to declare the variables function in Python?

Python is defined as a dynamically typed variable, which indicates that you have to declare what type each function variable is. In Python, variables do a storage placeholder during texts and numbers variable. It needs to convert one name so that you remain qualified to get this again. The variable does forever assign with an equal sign, replaced by the value of the variable function.

Q280) How do you reverse the string in python?

There is no such inbuilt function for this. The Easiest way for reversing the string in python is using slice which steps backwards, -1.
For example:
txt = “Hello World”[::-1] print(txt).

Q281) WAP to find the given string in the line?

This is the WAP for finding the given string in line.
Str = ‘Hello world’
If ‘hello’ in str:
Print ‘string found’.

Q282) What is class variable in python?

The Class variable are also known as static variables. These variables are shared by all objects. In Python the variables that are assigned the value in class declaration are known as class variables.

Q283) What is class in Python?

The python is “object oriented language”. Almost all the codes of this language are implemented using a special construct called Class. In simple words, “Class” is an object constructer in Python.

Q284) How can you handle multiple exception in python?

To handle multiple exception in python you can use try statement. You can also use these blocks:

  • The try/except blocks
  • The finally blocks
  • The raise keywords
  • Assertions
  • Defining your own exception

Q285) Can we write else statement try block in python?

Yes, it is possible to write else statement try block.
except IOError:
# we don’t want to catch the IOError if it’s raised

Q286) Does Python have do-while loop statements?

No, Python doesn’t have any do-while loop statements.

Q287) What is the difference between range and xrange in Python?

In python the range and xrange are two functions that are used repeat number of time in for loops. The major difference between rang and xrange is that the xrange returns the xrange object while the range returns a python list objects. The xrange is not capable for generating the static list at run-time. On the other hand range can do that.

Q288) Is it possible to inherit one class from another class?

Yes, we can inherit one class from another class in python.

Q289) Name different types of inheritance in python?

The inheritance refers to the capability of on class to derive the properties from other class. In python, there are two major types of inheritance.
Multiple Inheritance
Multilevel Inheritance

Q290) What is polymorphism?

The polymorphism in python refers to various types of respond to the same function. In Greek language the word poly means “many” and morphism means “forms”. This means that the same function name is being used on objects of different types.

Q291) How do you convert string as a variable name in python?

The simplest way to convert string as a variable name is by using vars().

Q292) Why do we want to use break statement in while-loop?

While-loop can convert into the infinite loop if you don’t use break statement.

Q293) Why we are using Def keyword for method?

The Def keyword in python is used to form a new user-defined function. The def keywords mark the beginning of function header. The functions are the objects through which one can easily organize the code.

Q294) Why are we using self as first argument?

The first argument represents the current instance of the class. The first argument is always called self. With the use of “self” keyword one can easily access the characteristics and methods of the class in python.

Q295) Why we are using a Python Dictionary?

There is huge collection of data values in the python dictionary. These dictionaries are accessed to retrieve the value of the keys that unknown to the users. There is a key: value pair provided in the dictionary which makes it more optimized.

Q296) What are the use of tuples in Python?

A tuple in python is a series of immutable Python objects. These tuples are similar to the list that are used for organizing data to make it easier to understand. If Python has created a tuple in memory, it difficult to change them.

Q297) What are the use of sets in Python?

The Python Set is the collection objects similar to lists and dictionaries. All the elements should be original and unique and must be immutable. The python sets in comparison with list provides highly optimized method for ensuring whether a specific element is contained in the set.

Q298) Does Python supports hybrid inheritance?

No, python doesn’t support hybrid inheritance. But we can use straight method and round diamond method we can achieve it.

Q299) What is the uses of middleware in Django?

Middleware is responsible for user authentication, session management .

Q300) Explain Deep Copy in Python

Answer: There are some values copied already. To store those copied values, Deep copy is used. Unlike Shallow copy, Deep copy will not copy the reference pointers.

Q301) Define the usage of split

Answer: If you want to separate a provided string in Python, use split() function.

Q302) What is the keyword to import a module in Python?

Answer: Use the keyword ‘import’ to import the modules in Python.

Q303) List out the different types of inheritance available in Python

Answer: Hierarchical inheritance, Multi-level inheritance, Multiple inheritance, and Single Inheritance are the four types inheritance available in Python.

Q304) Define monkey patching

Answer: You can make dynamic modifications to a module or class during the run-time. This process is called monkey patching in Python.

Q305) Explain encapsulation

Answer: Binding the data and code together is known as encapsulation. Example of encapsulation is a Python class.

Q306) Define Flask in Python

Answer: Flask, a microframework principally constructed for a minor application with easier requirements. External libraries must be used in Flask and flask is always ready to use state.

Q307) Define Pyramid in Python

Answer: For larger application, you can make use of Pyramid and this is hefty configurable concept. Pyramid affords suppleness and permits the developer to employ the appropriate tools for their assignment.

Q308) Define Django in Python

Answer: Similar to Pyramid, Django is built for larger applications and ORM is included.

Q309) Provide the Django MVT Pattern

Answer: Django Pattern

Q310) Why to use Python numpy instead o f lists?

Answer: Python numpy is convenient, less memory and rapid when compared to lists. Hence, it is better to use python numpy.

Q311) Mention the floor division available in Python

Answer: Double-slash (//) is the floor division in Python.

Q312) Is there any maximum length expected for an identifier?

Answer: No, there is no maximum length expected for an identifier as it can have any length.

Q313) Why do we say “a b c = 1000 2000 3000” is an invalid statement in Python?

Answer: We cannot have spaces in variable names and hence a b c = 1000 2000 3000 becomes invalid statement.

Q314) Mention the concept used in Python for memory managing

Answer: Python private heap space is the one used to manage memory.

Q315) What are the two (2) parameters available in Python map?

Answer: Iterable and function are the two (2) parameters available in Python map

Q316) Explain “with” statement in Python

Answer: As soon as there is a block of code, you can open and close a file using “with” statement in Python.

Q317) What are the modes to open a file in Python?

Answer: read–write mode (rw), write-only mode (w), and read-only mode (r) is the three (3) modes to open a file in Python.

Q318) Try to provide the command to open a file c:\welcome.doc for writing

Answer: Command to open a file for writing
f= open(“welcome.doc”, “wt”)

Q319) Explain Tkinter in Python

Answer: An inbuilt Python module helpful in creating GUI applications is known as Tkinter.