JOBSEEKERS
Login
Sign Up
Jobseeker
Employer
Staffing Firm
Direct Client
Python interview questions part 15
Python interview questions part 15
Back
Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. Identify the type of error in the codes shown below. Print(“Good Morning”) print(“Good night)
A. Syntax, Syntax
B. Semantic, Syntax
C. Semantic, Semantic
D. Syntax, Semantic
Show Correct Answer
Correct Answer is :
Semantic, Syntax
2. Which of the following statements is true?
A. The standard exceptions are automatically imported into Python programs
B. All raised standard exceptions must be handled in Python
C. When there is a deviation from the rules of a programming language, a semantic error is thrown
D. If any exception is thrown in try block, else block is executed
Show Correct Answer
Correct Answer is :
The standard exceptions are automatically imported into Python programs
3. Which of the following is not a standard exception in Python?
A. NameError
B. IOError
C. AssignmentError
D. ValueError
Show Correct Answer
Correct Answer is :
AssignmentError
4. Syntax errors are also known as parsing errors. Is this statement true or false?
A. TRUE
B. FALSE
C.
D.
Show Correct Answer
Correct Answer is :
TRUE
5. An exception is:
A. an object
B. a special function
C. a standard module
D. a module
Show Correct Answer
Correct Answer is :
an object
6. _______________________ exceptions are raised as a result of an error in opening a particular file.
A. ValueError
B. TypeError
C. ImportError
D. IOError
Show Correct Answer
Correct Answer is :
IOError
7. Which of the following blocks will be executed whether an exception is thrown or not?
A. except
B. else
C. finally
D. assert
Show Correct Answer
Correct Answer is :
finally
8. To open a file c:\scores.txt for reading, we use
A. infile = open(“c:\scores.txt”, “r”)
B. infile = open(“c:\\scores.txt”, “r”)
C. infile = open(file = “c:\scores.txt”, “r”)
D. infile = open(file = “c:\\scores.txt”, “r”)
Show Correct Answer
Correct Answer is :
infile = open(“c:\\scores.txt”, “r”)
9. To open a file c:\scores.txt for reading, we use
A. infile = open(“c:\scores.txt”, “r”)
B. infile = open(“c:\\scores.txt”, “r”)
C. infile = open(file = “c:\scores.txt”, “r”)
D. infile = open(file = “c:\\scores.txt”, “r”)
Show Correct Answer
Correct Answer is :
infile = open(“c:\\scores.txt”, “r”)
10. To open a file c:\scores.txt for writing, we use
A. outfile = open(“c:\scores.txt”, “w”)
B. outfile = open(“c:\\scores.txt”, “w”)
C. outfile = open(file = “c:\scores.txt”, “w”)
D. outfile = open(file = “c:\\scores.txt”, “w”)
Show Correct Answer
Correct Answer is :
outfile = open(“c:\\scores.txt”, “w”)
11. To open a file c:\scores.txt for writing, we use
A. outfile = open(“c:\scores.txt”, “w”)
B. outfile = open(“c:\\scores.txt”, “w”)
C. outfile = open(file = “c:\scores.txt”, “w”)
D. outfile = open(file = “c:\\scores.txt”, “w”)
Show Correct Answer
Correct Answer is :
outfile = open(“c:\\scores.txt”, “w”)
12. To open a file c:\scores.txt for appending data, we use
A. outfile = open(“c:\\scores.txt”, “a”)
B. outfile = open(“c:\\scores.txt”, “rw”)
C. outfile = open(file = “c:\scores.txt”, “w”)
D. outfile = open(file = “c:\\scores.txt”, “w”)
Show Correct Answer
Correct Answer is :
outfile = open(“c:\\scores.txt”, “a”)
13. To open a file c:\scores.txt for appending data, we use
A. outfile = open(“c:\\scores.txt”, “a”)
B. outfile = open(“c:\\scores.txt”, “rw”)
C. outfile = open(file = “c:\scores.txt”, “w”)
D. outfile = open(file = “c:\\scores.txt”, “w”)
Show Correct Answer
Correct Answer is :
outfile = open(“c:\\scores.txt”, “a”)
14. Which of the following statements are true?
A. When you open a file for reading, if the file does not exist, an error occurs
B. When you open a file for writing, if the file does not exist, a new file is created
C. When you open a file for writing, if the file exists, the existing file is overwritten with the new file
D. All of the mentioned
Show Correct Answer
Correct Answer is :
All of the mentioned
15. Which of the following statements are true?
A. When you open a file for reading, if the file does not exist, an error occurs
B. When you open a file for writing, if the file does not exist, a new file is created
C. When you open a file for writing, if the file exists, the existing file is overwritten with the new file
D. All of the mentioned
Show Correct Answer
Correct Answer is :
All of the mentioned
16. To read two characters from a file object infile, we use
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Show Correct Answer
Correct Answer is :
infile.read(2)
17. To read two characters from a file object infile, we use
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Show Correct Answer
Correct Answer is :
infile.read(2)
18. To read the entire remaining contents of the file as a string from a file object infile, we use
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Show Correct Answer
Correct Answer is :
infile.read()
19. To read the entire remaining contents of the file as a string from a file object infile, we use
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Show Correct Answer
Correct Answer is :
infile.read()
20. What is the output? f = Nonefor i in range (5): with open("data.txt", "w") as f: if i > 2: breakprint(f.closed)
A. TRUE
B. FALSE
C. None
D. Error
Show Correct Answer
Correct Answer is :
TRUE
Similar Interview Questions
Search for latest jobs
Find Jobs