Python Interview questions and answers for Experienced
Q. How many sequences are supported by Python?
A. Python supports 7 sequence types. They are str, list, tuple, unicode, byte array, xrange, and buffer.
where xrange is deprecated in python 3.5.X.
Q. How to display the contents of text file in reverse order?
A. convert the given file into a list.
reverse the list by using reversed()
Eg: for line in reversed(list(open(“file-name”,”r”))):
print(line)
Q. Which of the following is an invalid statement in python?
A. a) abc = 2,000,000
b) a b c = 2000 3000 4000
c) a,b,c = 2000, 3000, 4000
d) a_b_c = 2,000,000
Answer: b
Q. Write reverse a list in Python?
A. list.reverse()
Reverses objects of list in place.
Q. To read a file c:\log.txt for reading?
A. fileReader = open(“c:\\log.txt”, “r”)
Note: this is the path is defined shown here for local system it differ for online and relative network paths.