Q: The assignment of more than one function to a particular operator is _______
Solution: The assignment of more than one function to a particular operator is called as operator overloading.
Q: Which of the following is not a class method?
Solution: The three different class methods in Python are static, bounded and unbounded methods.
Q: What will be the output of the following Python code? def add(c,k): c.test=c.test+1 k=k+1 class A: def __init__(self): self.test = 0 def main(): Count=A() k=0 for i in range(0,25): add(Count,k) print("Count.test=", Count.test) print("k =", k) main()
Solution: The program has no error. Here, test is a member of the class while k isn’t. Hence test keeps getting incremented 25 time while k remains 0.
Q: Which of the following Python code creates an empty class?
Solution: Execute in python shell to verify.
Q: Is the following Python code valid? class B(object): def first(self): print("First method called") def second(): print("Second method called") ob = B() B.first(ob)
Solution: The method may be created in the method demonstrated in the code as well and this is called as the unbounded method call. Calling the method using obj.one() is the bounded method call.
Q: What are the methods which begin and end with two underscore characters called?
Solution: Special methods like __init__ begin and end with two underscore characters.
Q: Special methods need to be explicitly called during object creation.
Solution: Special methods are automatically called during object creation.
Q: What is hasattr(obj,name) used for?
Solution: hasattr(obj,name) checks if an attribute exists or not and returns True or False.
You Have Score    | /8 |