python irerview question and answers
python irerview question and answers
- Python follows a depth-first lookup order and hence ends up calling the
method from class A. By following the method resolution order, the lookup
order as follows. Python follows depth-first order to resolve the methods
and attributes.
ans: shallow copy:will take a copy of the original object and create a
new compound object but if the object we are copying is a compound
object the inner
objects will be the same as the ones found in the original object.
deep copy: A deep copy will take a copy of the original object and
will then recursively take copy of the inner objects which are found (if
any)
- What is 'init' keyword in python?
This method called when an object is created from the class and it
allow the class to initialize the attributes of a class
class it does not have to be named self you can call whatever you
like but it has to be the first parameter of any function in class
What is polymorphism? Polymorphism refers to having
multiple forms. Polymorphism is a programming term
that refers to the use of the same function name, but with
different signatures, for multiple types.
ans: A child class inherits all the methods from the parent class.
However, in some situations
the method inherited from the parent class doesn’t quite fit into the
child class. In such cases, you will
ans: Two methods cannot have the same name in Python; hence
method overloading is a feature that allows the same operator to have
different meanings
ans: the default arguments is nothing but when you use parameter
inside the function but you didn't call parameter
Suppose you want to terminate a loop and skip to the next code
after the loop; break will help you do that
ans:list and tuple are heterogeneous ordered data type means we can
assign any type of values like int,string,flot,complex
but lists are mutable datatype and tuple are immutable datatype we
cannot update once we assign the value
- What is dictnorys in python?
print(even_nums)
values=[1,2,3,4,5,6,7,8,9,10]
print(NewDictionary)
ans: iterators:
The iterator simply implements the Python's iterator protocol. The iterator
protocol is a Python class which comes with two special methods,
namely __iter__() and __next__() . With these two methods, the iterator is
able to compute the next value in the iteration.
Generators:
A package must hold the file __init__.py. This does not apply to
modules.
ans: the diffference resides in memory when using range() the entire
list will be allocated in memory where as xrange() returns a
genarator(actually it returns an xrange object
-What is Polymorphism?
ans: numirical(int,flot,complex)
sequence(list,tuple dictinories)
boolen(true,false)
sets
dictionary
ans: global varibles are declared outside of the function and local are
declared inside the function while global varibles cannot be directly
changed in the function
you can use global keyword to creat a function that will change the
value of global varible
class it does not have to be named self you can call whatever you
like but it has to be the first parameter of any function in class
ans:
Ans: In Python, you can access a file by using the open() method. However,
using the open() method directly requires you to use the close() method to
close the file explicitly. Instead, you can create a context using the with Open
statement in python. It returns a file object, which has methods and attributes
for getting information about and manipulating the opened file
- What is Pythonpath?
- How exception handled in Python. [Try, Except, Else And Finally Block]
- Bonus Tip