1. How do you get the current position within the file?
Correct Answer is : fp.tell()
2. How do you rename a file?
Correct Answer is : os.rename(existing_name, new_name)
3. How do you delete a file?
Correct Answer is : os.remove(‘file’)
4. How do you change the file position to an offset value from the start?
Correct Answer is : fp.seek(offset, 0)
5. What happens if no arguments are passed to the seek function?
Correct Answer is : error
6. What is the output of the code snippet shown below?
X=”hi”
print(“05d”%X)
Correct Answer is : error
7. Consider the snippet of code shown below and predict the output.
X=”san-foundry”
print(“%56s”,X)
Correct Answer is : 56 blank spaces before san-foundry
8. What is the output of the following expression if x=456?
print("%-06d"%x)
9. What is the output of the following expression if X=345?
print(“%06d”%X)
10. Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?
Correct Answer is : print(“%-ns”%S)
11. What is the output of this expression if X= -122?
print("-%06d"%x)
12. What is the output of the following expression if the value of x is 34?
print(“%f”%x)
13. What is the result of the expression shown below if x=56.236?
print("%.2f"%x)
Correct Answer is : 56.24
14. What is the output of this expression if x=22.19?
print("%5.2f"%x)
Correct Answer is : 22.19
15. The expression shown below results in an error. State whether this statement is true or false.
print("-%5d0",989)
Correct Answer is : FALSE
16. The output of the snippet of code shown below is:
'%d %s %g you' %(1, 'hello', 4.0)
Correct Answer is : 1 hello 4 you
17. The output of which of the codes shown below will be: “There are 4 blue birds.”?
Correct Answer is : ‘There are %d %s birds.’ %(4, blue)
18. What is the output of the code shown below if the system date is 18th August, 2016?
x=1234
res='integers:...%d...%-6d...%06d' %(x, x, x)
res
Correct Answer is : ‘integers:…1234…1234 …001234’
19. What is the output of the code shown?
x=3.3456789
'%f | %e | %g' %(x, x, x)
Correct Answer is : ‘3.345679 | 3.345679e+00 | 3.34568’
20. What is the output of the code shown below?
x=3.3456789
'%-6.2f | %05.2f | %+06.1f' %(x, x, x)
Correct Answer is : ‘3.35 | 03.35 | +003.3’