Share on facebook
Share on twitter
Share on pinterest

Python interview questions are designed for freshers & experienced professionals to help to prepare for upcoming Python Interviews.

Python Interview Questions

Where is the (,, etc.) source file?

To quickly check where a module is located, import it and check the module’s __file__ attribute:

>>> import math
>>> math.__file__
>>> import random
>>> random.__file__

If this gives you an AttributeError exception, the module is built into the interpreter.

What is the key difference between a List and a Tuple?

The main difference is that a List is mutable in Python whereas Tuple is immutable. And from memory consumption perspective, a List consumes more memory than a Tuple.

Read more.

How to Call Base Class Method From a Derived Class?

For old-style classes:

BaseClassName.methodname(self, arguments)
>>> class A:

...    def hello(self):

...        print 'a'


>>> A().hello()


>>> class C(A):

...    def hello(self):

...        A.hello(self)

...        print 'c'


>>> C().hello()


For new-style class:

super(ClassName, self).method(args)
>>> class M(object):

...    def hello(self):

...        print 'm'


>>> class N(M):

...    def hello(self):

...        super(N, self).hello()

...        print 'n'


>>> N().hello()


Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *