Python Interview Questions

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.


It will give output as below


Q64. What is the ideal way to copy sequences?

Ans : You should use slicing to copy sequence as below


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?

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.


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).

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

Premium Training : Spark Full Length Training : with Hands On Lab

Previous Next

Home Spark Hadoop NiFi Java

Disclaimer :

1. Hortonworks® is a registered trademark of Hortonworks.

2. Cloudera® is a registered trademark of Cloudera Inc

3. Azure® is aregistered trademark of Microsoft Inc.

4. Oracle®, Java® are registered trademark of Oracle Inc

5. SAS® is a registered trademark of SAS Inc

6. IBM® is a registered trademark of IBM Inc

7. DataStax ® is a registered trademark of DataStax

8. MapR® is a registered trademark of MapR Inc.

2014-2017 © | Dont Copy , it's bad Karma |