Wednesday, December 30, 2015

Python Interview questions

1. What is constructors in python?
2. How do inherit in python?
3. Name the types of datatypes in python?

Python has five standard data types:
1. Numbers
2. Strings
3. List
4. Tuple
5. Dictionary

Python supports four different numerical types:
1. int (signed integers)
2. long (long integers, they can also represented in octal and hexa decimal)
3. Float
4. Complex


4. Name the types of  variables in python? and how to configure the private, public variables and how to access them?

5. How do you reverse the string?


How do you login the webpage using python scripting without selenium web driver?

6. Write a class that keeps track of all the identifiers of objects created while instantiating?

7. Write a method that takes two dimensional list as argument and gives the transpose of the list
(Eg:)
def transpose(input_list):
    #Your Code here
    return output_list

a = [[1,2,3],[4,5,6]]


print transpose(a)
#Outputs[[1,4],[2,5],[3,6]]

8. Read a file and print only the strings from the file.

def Main():
        with open('word.txt','r') as f:
                for line in f:
                        for i in line.split(" "):
                                for x in i.rstrip("\n").split():
                                        if x.isalpha() == True:
                                                print x


if __name__ == "__main__":
        Main()


9. Write a class which implements method overloading?

10. What is the output of the following code?

def fun1(a=None):
    print "In the first function"

def fun1(a):
   print "In the second function"