python quiz 9 on June 26, 2021 Get link Facebook X Pinterest Email Other Apps Q:1. If we have a file object as fileobj, then What does the attribute 'closed' will tell on this file obj ?1.tells (True of False) whether theFile is closed or not2.Reads and return ‘something’3.read a single line from theFile, including the newline character4.modify the file object for theFile so that the next read will be fromANSWER :- (1) Here CLOSED attribute will returns a boolean stating whether the file is closed or not , in form of true and false.Q:2. In python, _____ method gets the position of file handle while ____ method changes the position of file handle to the specific position.1.seek, tell2.tell, seek3.read, tell4.tell, changeANSWER :- (2) In Python, tell() returns the current position of the file pointer from the beginning of the file. while seek() function is used to change the position of the File Handle to a given specific position.Q:3. What will be the output of the following given code? with open("myfile.txt", "w") as f: f.write("Hello World Python Programming") with open('myfile.txt', 'w+') as f: f.write("Hello") f.seek(0) data = f.readlines() for line in data: words = line.split() print (words) 1.['Hello']2.['Hello World Python Programming']3.['Hello', 'World', 'Python', 'Programming']4.Runtime ErrorANSWER :- (1) Here program returns only hello.Q:4. In the readlines() method -1.it returns a string.2.it returns a list of lines.3.an optional parameter sizehint can be used to limit the number of bytes to read from a file.4.Both 2 and 3ANSWER :- (4) Readlines() is used to read all the lines at a single go and then return them as each line a string element in a list. This function can be used for small files, as it reads the whole file content to the memory, then split it into separate lines. If the total number of bytes returned exceeds the specified number, no more lines are returned.Q:5. In python, try-except has an optional else clause, which will execute -1.always.2.when try clause does not raise exception.3.when OSError happens.4.All of the above.ANSWER :- (4) Here in python try-except has an optional else clause, which will execute always, when try clause does not raise exception and when OS Error.stay updated for next quiz only at :-hi-tutorial.blogspot.com Comments
Comments
Post a Comment