NOTE -ANSWERS ARE AT THE BOTTOM OF THE PAGE
Q:1. If we have a file object as fileobj, then What does the attribute 'closed' will tell on this file obj ?
1.
2.
3.
4.
Q:2. In python, _____ method gets the position of file handle while ____ method changes the position of file handle to the specific position.
1.
2.
3.
4.
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.
2.
3.
4.
Q:4. In the readlines() method -
1.
2.
3.
4.
Q:5. In python, try-except has an optional else clause, which will execute -
1.
2.
3.
4.
Answers
1-a)It is read only property and returns a Boolean value( true or false).The value is true if file is closed and false if not closed.
2-b)These are pre-defined/inbuilt. methods in python.
3-a)The program first opens 'myfile.txt' and writes 'hello world Python programming' but it also writes after this again and writes 'hello'.
4-d)Readlines method is used to read a list of lines in a file and we can also limit the number of lines returned by it using the Sizehint parameters.
5-d)All the options are correct because except keyword is used for exceptions and we can always use it whether program executes, an OSerror happens or try clause doesn't raise exception.
0 Comments