| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which of the following is not a class method?

Correct Answer is : Non-static

2. What is the output of the following code? 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()

Correct Answer is : Count.test=25

3. Which piece of code creates an empty class?

Correct Answer is : class A: pass

4. Is the following piece of code valid? class B(object): def first(self): print("First method called") def second(): print("Second method called") ob = B() B.first(ob)

Correct Answer is : Yes, this method of calling is called unbounded method call

5. What are the methods which begin and end with two underscore characters called?

Correct Answer is : Special methods

6. Special methods need to be explicitly called during object creation. True or False?

Correct Answer is : FALSE

7. What is the output of the following code? >>> class demo(): def __repr__(self): return '__repr__ built-in function called' def __str__(self): return '__str__ built-in function called' >>> s=demo() >>> s

Correct Answer is : __repr__ called

8. What is the output of the following code? >>> class demo(): def __repr__(self): return '__repr__ built-in function called' def __str__(self): return '__str__ built-in function called' >>> s=demo() >>> print(s)

Correct Answer is : __str__ called

9. What is hasattr(obj,name) used for?

Correct Answer is : To check if an attribute exists or not

10. What is the output of the following piece of code? class stud: def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) stud1 = stud(34, ‘S’) stud1.age=7 print(hasattr(stud1, 'age'))

Correct Answer is : Error as age isn’t defined

11. What is delattr(obj,name) used for?

Correct Answer is : To delete an attribute

12. __del__ method is used to destroy instances of a class. True or False?

Correct Answer is : TRUE

13. What is the output of the following piece of code? class stud: ‘Base class for all students’ def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) print(student.__doc__)

Correct Answer is : Base class for all students

14. What does print(Test.__name__) display (assuming Test is the name of the class) ?

Correct Answer is : Test

15. Which of these in not a core data type?

Correct Answer is : Class

16. Given a function that does not return any value, What value is thrown by default when executed in shell.

Correct Answer is : None

17. Following set of commands are executed in shell, what will be the output? >>>str="hello">>>str[:2]>>>

Correct Answer is : he

18. Which of the following will run without errors ?

Correct Answer is : round(45.8)

19. What is the return type of function id?

Correct Answer is : int

20. What error occurs when you execute? apple = mango

Correct Answer is : NameError