JOBSEEKERS
Login
Sign Up
Jobseeker
Employer
Staffing Firm
Direct Client
Python interview questions part 18
Python interview questions part 18
Back
Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. How do you get the current position within the file?
A. fp.seek()
B. fp.tell()
C. fp.loc
D. fp.pos
Show Correct Answer
Correct Answer is :
fp.tell()
2. How do you rename a file?
A. fp.name = ‘new_name.txt’
B. os.rename(existing_name, new_name)
C. os.rename(fp, new_name)
D. os.set_name(existing_name, new_name)
Show Correct Answer
Correct Answer is :
os.rename(existing_name, new_name)
3. How do you delete a file?
A. del(fp)
B. fp.delete()
C. os.remove(‘file’)
D. os.delete(‘file’)
Show Correct Answer
Correct Answer is :
os.remove(‘file’)
4. How do you change the file position to an offset value from the start?
A. fp.seek(offset, 0)
B. fp.seek(offset, 1)
C. fp.seek(offset, 2)
D. none of the mentioned
Show Correct Answer
Correct Answer is :
fp.seek(offset, 0)
5. What happens if no arguments are passed to the seek function?
A. file position is set to the start of file
B. file position is set to the end of file
C. file position remains unchanged
D. error
Show Correct Answer
Correct Answer is :
error
6. What is the output of the code snippet shown below? X=”hi” print(“05d”%X)
A. 00000hi
B. 000hi
C. hi000
D. error
Show Correct Answer
Correct Answer is :
error
7. Consider the snippet of code shown below and predict the output. X=”san-foundry” print(“%56s”,X)
A. 56 blank spaces before san-foundry
B. 56 blank spaces before san and foundry
C. 56 blank spaces after san-foundry
D. no change
Show Correct Answer
Correct Answer is :
56 blank spaces before san-foundry
8. What is the output of the following expression if x=456? print("%-06d"%x)
A. 456
B. 456000
C. 456
D. error
Show Correct Answer
Correct Answer is :
456
9. What is the output of the following expression if X=345? print(“%06d”%X)
A. 345000
B. 345
C. 345
D. 345000000
Show Correct Answer
Correct Answer is :
345
10. Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?
A. print(“-ns”%S)
B. print(“-ns”%S)
C. print(“%ns”%S)
D. print(“%-ns”%S)
Show Correct Answer
Correct Answer is :
print(“%-ns”%S)
11. What is the output of this expression if X= -122? print("-%06d"%x)
A. -122
B. 122
C. -122
D. -122
Show Correct Answer
Correct Answer is :
-122
12. What is the output of the following expression if the value of x is 34? print(“%f”%x)
A. 34
B. 34
C. 34
D. 34
Show Correct Answer
Correct Answer is :
34
13. What is the result of the expression shown below if x=56.236? print("%.2f"%x)
A. 56
B. 56.24
C. 56.23
D. 56.236
Show Correct Answer
Correct Answer is :
56.24
14. What is the output of this expression if x=22.19? print("%5.2f"%x)
A. 22.19
B. 22
C. 22.19
D. 22.2
Show Correct Answer
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)
A. TRUE
B. FALSE
C.
D.
Show Correct Answer
Correct Answer is :
FALSE
16. The output of the snippet of code shown below is: '%d %s %g you' %(1, 'hello', 4.0)
A. Error
B. 1 hello you 4.0
C. 1 hello 4 you
D. 1 4 hello you
Show Correct Answer
Correct Answer is :
1 hello 4 you
17. The output of which of the codes shown below will be: “There are 4 blue birds.”?
A. ‘There are %g %d birds.’ %4 %blue
B. ‘There are %d %s birds.’ %(4, blue)
C. ‘There are %s %d birds.’ %[4, blue]
D. ‘There are %d %s birds.’ 4, blue
Show Correct Answer
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
A. ‘integers:…1234…1234 …001234’
B. ‘integers…1234…1234…123400’
C. ‘integers:… 1234…1234…001234’
D. ‘integers:…1234…1234…001234’
Show Correct Answer
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)
A. Error
B. ‘3.3456789 | 3.3456789+00 | 3.345678’
C. ‘3.345678 | 3.345678e+0 | 3.345678’
D. ‘3.345679 | 3.345679e+00 | 3.34568’
Show Correct Answer
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)
A. ‘3.35 | 03.35 | +003.3’
B. ‘3.3456789 | 03.3456789 | +03.3456789’
C. Error
D. ‘3.34 | 03.34 | 03.34+’
Show Correct Answer
Correct Answer is :
‘3.35 | 03.35 | +003.3’
Similar Interview Questions
Search for latest jobs
Find Jobs