Python interview questions part 17

Python interview questions part 17

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

Total Questions: 20

1. What is unpickling?

Correct Answer is : It is used for object deserialization

2. What is the correct syntax of open() function?

Correct Answer is : file object = open(file_name [, access_mode][, buffering])

3. What is the output of this program? fo = open("foo.txt", "wb")print "Name of the file: ", fo.namefo.flush()fo.close()

Correct Answer is : Flushes the file when closing them

4. Correct syntax of file.writelines() is?

Correct Answer is : fileObject.writelines(sequence)

5. Correct syntax of file.readlines() is?

Correct Answer is : fileObject.readlines( sizehint );

6. In file handling, what does this terms means “r, a”?

Correct Answer is : read, append

7. What is the use of “w” in file handling?

Correct Answer is : Write

8. What is the use of “a” in file handling?

Correct Answer is : Append

9. Which function is used to read all the characters?

Correct Answer is : Read()

10. Which function is used to read single line from file?

Correct Answer is : Readlines()

11. Which function is used to write all the characters?

Correct Answer is : write()

12. Which function is used to write a list of string in a file

Correct Answer is : writeline()

13. Which function is used to close a file in python?

Correct Answer is : Close()

14. Is it possible to create a text file in python?

Correct Answer is : Yes

15. Which of the following is modes of both writing and reading in binary format in file.?

Correct Answer is : wb+

16. Which of the following is not a valid mode to open a file?

Correct Answer is : rw

17. What is the difference between r+ and w+ modes?

Correct Answer is : in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+

18. How do you get the name of a file from a file object (fp)?

Correct Answer is : fp.name

19. Which of the following is not a valid attribute of a file object (fp)?

Correct Answer is : fp.size

20. How do you close a file object (fp)?

Correct Answer is : fp.close()

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon