My Report

Python File Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What is the current syntax of remove() a file?

2. What will be the output of the following Python code?

fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name

# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line

for index in range(5):
   line = fo.next()
   print "Line No %d - %s" % (index, line)

# Close opened file
fo.close()

3. What will be the output of the following Python code?

str = input("Enter your input: ");
print "Received input is : ", str

4. What is the use of seek() method in files?

5. Which one of the following is not attributes of file?

6. What is the use of truncate() method in file?

7. What is the current syntax of rename() a file?

8. Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?

9. What is the use of tell() method in python?

10. What will be the output of the following Python code?

str = raw_input("Enter your input: ");
print "Received input is : ", str

 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.