Learn Python in Less than 8 Hrs Sitting @ Home /Desk with HandsOn

Q61. How do you find, if two variables are pointing to the same object or not?

Ans: You should have used is operator or build-in function id().

Q62. How can you return more than 1 value from a function?

Ans : You should have used tuple as a return value. If you want more than 1 value as a return value.

Q63. What do you mean by Higher-order function?

Ans : A function, which can accept other function as an arguments and return function to the caller is known as higher order fi=unction. See the example below.

 def doOperation(a,b):     def operation(x):         return (a+x) *(b+x)     return operation Here, doOperation function take two arguments a and b as input and return operation function as an output.  So you call the function as below.

 result=doOperation(5,10) result(10)

It will give output as below

(5+10)*(10+10)=(15)*(20)=300

Q64. What is the ideal way to copy sequences?

Ans : You should use slicing to copy sequence as below

New_list=old_list[:]

Q65. Which method will you use to find all the methods and attributes of an Object of a class?

Ans : We will be using either help() or dir() method.

Q66. How is the below statement will be evaluated?

“x” in “a” , “x”

Ans : Please note that comma is not an operator. It is a separator. Hence, above statement will be evaluated as below.

(“x” in “a”) , “x”

And result will be as below

(False, “x”)

Q67. What is the value of below expression?

X=100

Y=20

Val = X if X < Y else Y

Ans: Here Val will have 20. Because first condition is false, which will result in Y, which is 20.

Q68. How will you remove the duplicate elements from the list?

Ans: It’s very simple, as we know set contain only unique values. Hence, first convert list to set and then set back to list.

 list(set(list_with_duplicates)) Q69. What is a Class?

Ans : You can say, it is a user defined object. It works as a template and hold attributes and functions.

Q70. What is self?

Ans: Self is a first argument of a method. A method defined as do_something(self, a, b, c) should be called as object.do_something(a, b, c) for some instance object of the class in which the definition occurs; the called method will think it is called as do_something(self, a, b, c).