Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Document Name – Python Technical Interview (part 1)

Author – Ashima Sethi


Email : codingmente@hotmail.com

Q1 : What is the difference between list and tuple?


List is mutuable and tuple is immutable. That means values in the list can be changed using
append or extend or simple assigning values but in tuple we cannot do that thing

For ex:
L1 = [1,2,3,4]
T1 = (1,2,3,4)
L1[0] = 5
Print(L1)
Output: [5,2,3,4]

But in tuple
T1[0] = 5
Error: ‘Tuple’ object doesnot support item assignment

Q2: Difference B/W shallow and deep Copy in python?


Deep copy is a process in which the copying process occurs recursively. It
means first constructing a new collection object and then recursively
populating it with copies of the child objects found in the original. In case of
deep copy, a copy of object is copied in other object. It means that any
changes made to a copy of object do not reflect in the original object.

A shallow copy means constructing a new collection object and then


populating it with references to the child objects found in the original. The
copying process does not recurse and therefore won’t create copies of the
child objects themselves. In case of shallow copy, a reference of object is
copied in other object. It means that any changes made to a copy of
object do reflect in the original object. In python, this is implemented using
“copy()” function.

Q3: What are decorators in python?


Decorators allow us to wrap another function in order to extend the
behaviour of the wrapped function, without permanently modifying it.
def shout(text):
return text.upper()

def whisper(text):
return text.lower()

def greet(func):
# storing the function in a variable
greeting = func("""Hi, I am created by a function passed as an
argument.""")
print (greeting)

greet(shout)
greet(whisper)

Q4: What are generators in python?


Python provides a generator to create your own iterator function. A generator
is a special type of function which does not return a single value, instead, it
returns an iterator object with a sequence of values. In a generator function,
a yield statement is used rather than a return statement.

Q5: How can we add two tuples in Python?


By using ‘+’ assignment operator in python

Q5: What is pickling and unpickling in python?


Pickling is : It is a process where a Python object hierarchy is
converted into a byte stream.
UnPickling is : It is the inverse of Pickling process where a
byte stream is converted into an object hierarchy.

To know more questions like this Please visit:


https://codingmente.com/pdfs/

You might also like