Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What is the output?
f = Nonefor i in range (5): with open("data.txt", "w") as f: if i > 2: breakprint(f.closed)
Correct Answer is : TRUE
2. To read the next line of the file from a file object infile, we use
Correct Answer is : infile.readline()
3. To read the next line of the file from a file object infile, we use
Correct Answer is : infile.readline()
4. To read the remaining lines of the file from a file object infile, we use
Correct Answer is : infile.readlines()
5. To read the remaining lines of the file from a file object infile, we use
Correct Answer is : infile.readlines()
6. The readlines() method returns
Correct Answer is : a list of lines
7. The readlines() method returns
Correct Answer is : a list of lines
8. Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?
Correct Answer is : Raw_input & Input
9. What is the output of this program?
str = raw_input("Enter your input: ");print "Received input is : ", str
Correct Answer is : Enter your input: Hello Python
10. What is the output of this program?
str = input("Enter your input: ");print "Received input is : ", str
Correct Answer is : Enter your input: [x*5 for x in range(2,10,2)].
11. Which one of the following is not attributes of file
Correct Answer is : rename
12. What is the use of tell() method in python?
Correct Answer is : tells you the current position within the file
13. What is the current syntax of rename() a file?
Correct Answer is : rename(current_file_name, new_file_name)
14. What is the current syntax of remove() a file?
Correct Answer is : remove(file_name)
15. What is the output of this program?
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 filefo.close()
Correct Answer is : Displays Output
16. What is the use of truncate() method in file?
Correct Answer is : truncates the file size
17. Which is/are the basic I/O connections in file?
Correct Answer is : All of the mentioned
18. What is the output of this program?
import sysprint 'Enter your name: ',name = ''while True: c = sys.stdin.read(1) if c == '\n': break name = name + c print 'Your name is:', name
If entered name is
sanfoundry
Correct Answer is : sanfoundry
19. What is the output of this program?
import syssys.stdout.write(' Hello\n')sys.stdout.write('Python\n')
Correct Answer is : Hello
20. What is the pickling?
Correct Answer is : It is used for object serialization