

InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
1. |
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) errorI got this question in semester exam.My doubt is from Files in section Regular Expressions and Files of Python |
Answer» The CORRECT OPTION is (d) error |
|
2. |
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 mentionedThe question was asked during an interview for a job.Enquiry is from Files topic in portion Regular Expressions and Files of Python |
Answer» RIGHT answer is (a) fp.seek(offset, 0) EXPLANATION: 0 indicates that the offset is with RESPECT to the start. |
|
3. |
How do you delete a file?(a) del(fp)(b) fp.delete()(c) os.remove(‘file’)(d) os.delete(‘file’)The question was posed to me by my college director while I was bunking the class.This interesting question is from Files topic in portion Regular Expressions and Files of Python |
Answer» Right CHOICE is (c) os.remove(‘file’) |
|
4. |
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)This question was addressed to me in an online quiz.This question is from Files in chapter Regular Expressions and Files of Python |
Answer» The correct ANSWER is (B) os.RENAME(existing_name, new_name) |
|
5. |
How do you get the current position within the file?(a) fp.seek()(b) fp.tell()(c) fp.loc(d) fp.posI have been asked this question during an interview.This intriguing question originated from Files in division Regular Expressions and Files of Python |
Answer» Right ANSWER is (B) fp.tell() |
|
6. |
How do you close a file object (fp)?(a) close(fp)(b) fclose(fp)(c) fp.close()(d) fp.__close__()I had been asked this question in a job interview.My question is taken from Files topic in portion Regular Expressions and Files of Python |
Answer» Right CHOICE is (c) fp.close() |
|
7. |
Which of the following is not a valid attribute of a file object (fp)?(a) fp.name(b) fp.closed(c) fp.mode(d) fp.sizeI had been asked this question during an interview for a job.I would like to ask this question from Files in section Regular Expressions and Files of Python |
Answer» CORRECT ANSWER is (d) fp.size Easiest EXPLANATION - fp.size has not been IMPLEMENTED. |
|
8. |
How do you get the name of a file from a file object (fp)?(a) fp.name(b) fp.file(name)(c) self.__name__(fp)(d) fp.__name__()I had been asked this question in class test.Query is from Files topic in portion Regular Expressions and Files of Python |
Answer» Right choice is (a) fp.name |
|
9. |
What is the difference between r+ and w+ modes?(a) no difference(b) in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+(c) in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+(d) depends on the operating systemThis question was addressed to me in semester exam.Query is from Files in chapter Regular Expressions and Files of Python |
Answer» CORRECT choice is (b) in R+ the pointer is INITIALLY placed at the beginning of the file and the pointer is at the end for w+ The EXPLANATION: none. |
|
10. |
Which of the following is not a valid mode to open a file?(a) ab(b) rw(c) r+(d) w+I got this question by my school principal while I was bunking the class.I need to ask this question from Files topic in section Regular Expressions and Files of Python |
Answer» The CORRECT option is (b) rw |
|
11. |
Which of the following are the modes of both writing and reading in binary format in file?(a) wb+(b) w(c) wb(d) w+This question was posed to me in an interview for internship.The question is from Files topic in portion Regular Expressions and Files of Python |
Answer» The correct CHOICE is (a) wb+ |
|
12. |
Is it possible to create a text file in python?(a) Yes(b) No(c) Machine dependent(d) All of the mentionedI have been asked this question in semester exam.My doubt stems from Files topic in division Regular Expressions and Files of Python |
Answer» The correct choice is (a) YES |
|
13. |
Which function is used to write a list of string in a file?(a) writeline()(b) writelines()(c) writestatement()(d) writefullline()This question was posed to me in an online interview.This question is from Files in section Regular Expressions and Files of Python |
Answer» The correct answer is (a) writeline() |
|
14. |
Which function is used to close a file in python?(a) Close()(b) Stop()(c) End()(d) Closefile()I had been asked this question during an online exam.My enquiry is from Files topic in chapter Regular Expressions and Files of Python |
Answer» Right CHOICE is (a) Close() |
|
15. |
Which function is used to write all the characters?(a) write()(b) writecharacters()(c) writeall()(d) writechar()The question was asked in an online interview.This question is from Files in section Regular Expressions and Files of Python |
Answer» Right option is (a) WRITE() |
|
16. |
Which function is used to read single line from file?(a) Readline()(b) Readlines()(c) Readstatement()(d) Readfullline()The question was posed to me by my college director while I was bunking the class.This question is from Files in division Regular Expressions and Files of Python |
Answer» The CORRECT choice is (b) Readlines() |
|
17. |
Which function is used to read all the characters?(a) Read()(b) Readcharacters()(c) Readall()(d) Readchar()I had been asked this question in class test.My question is based upon Files topic in division Regular Expressions and Files of Python |
Answer» Correct CHOICE is (a) READ() |
|
18. |
What is the use of “a” in file handling?(a) Read(b) Write(c) Append(d) None of the mentionedI have been asked this question during an interview.My query is from Files topic in chapter Regular Expressions and Files of Python |
Answer» Right choice is (c) Append |
|
19. |
What is the use of “w” in file handling?(a) Read(b) Write(c) Append(d) None of the mentionedThe question was asked during a job interview.The above asked question is from Files topic in division Regular Expressions and Files of Python |
Answer» RIGHT choice is (b) Write The BEST I can EXPLAIN: This opens the file for writing. It will create the file if it doesn’t exist, and if it does, it will overwrite it. fh = open(“filename_here”, “w”). |
|
20. |
In file handling, what does this terms means “r, a”?(a) read, append(b) append, read(c) write, append(d) none of the mentionedI have been asked this question in exam.I need to ask this question from Files in portion Regular Expressions and Files of Python |
Answer» The CORRECT ANSWER is (a) read, append |
|
21. |
Correct syntax of file.readlines() is?(a) fileObject.readlines( sizehint );(b) fileObject.readlines();(c) fileObject.readlines(sequence)(d) none of the mentionedI got this question by my school principal while I was bunking the class.I want to ask this question from Files in division Regular Expressions and Files of Python |
Answer» The correct answer is (a) fileObject.READLINES( sizehint ); |
|
22. |
What is the correct syntax of open() function?(a) file = open(file_name [, access_mode][, buffering])(b) file object = open(file_name [, access_mode][, buffering])(c) file object = open(file_name)(d) none of the mentionedI have been asked this question in an online interview.Enquiry is from Files in division Regular Expressions and Files of Python |
Answer» Correct option is (b) file object = open(file_name [, access_mode][, buffering]) |
|
23. |
Correct syntax of file.writelines() is?(a) file.writelines(sequence)(b) fileObject.writelines()(c) fileObject.writelines(sequence)(d) none of the mentionedI have been asked this question in a national level competition.I need to ask this question from Files in chapter Regular Expressions and Files of Python |
Answer» Right ANSWER is (c) fileObject.WRITELINES(sequence) |
|
24. |
What is unpickling?(a) It is used for object serialization(b) It is used for object deserialization(c) None of the mentioned(d) All of the mentionedI have been asked this question in unit test.The above asked question is from Files in section Regular Expressions and Files of Python |
Answer» Correct choice is (b) It is USED for object deserialization |
|
25. |
What is the pickling?(a) It is used for object serialization(b) It is used for object deserialization(c) None of the mentioned(d) All of the mentionedThe question was asked in class test.The above asked question is from Files topic in division Regular Expressions and Files of Python |
Answer» RIGHT answer is (a) It is used for object serialization The explanation: Pickle is the standard MECHANISM for object serialization. Pickle uses a simple stack-based virtual machine that records the instructions used to reconstruct the object. This makes pickle vulnerable to SECURITY risks by malformed or maliciously CONSTRUCTED data, that MAY cause the deserializer to import arbitrary modules and instantiate any object. |
|
26. |
What is the use of truncate() method in file?(a) truncates the file size(b) deletes the content of the file(c) deletes the file size(d) none of the mentionedThis question was addressed to me by my school teacher while I was bunking the class.Question is from Files topic in chapter Regular Expressions and Files of Python |
Answer» The CORRECT answer is (a) truncates the FILE SIZE |
|
27. |
What is the use of seek() method in files?(a) sets the file’s current position at the offset(b) sets the file’s previous position at the offset(c) sets the file’s current position within the file(d) none of the mentionedThis question was addressed to me during an interview.My doubt stems from Files topic in portion Regular Expressions and Files of Python |
Answer» Correct choice is (a) sets the file’s current position at the OFFSET |
|
28. |
What is the current syntax of remove() a file?(a) remove(file_name)(b) remove(new_file_name, current_file_name,)(c) remove(() , file_name))(d) none of the mentionedI had been asked this question in homework.My question is taken from Files topic in chapter Regular Expressions and Files of Python |
Answer» CORRECT OPTION is (a) REMOVE(file_name) The EXPLANATION: remove(file_name) |
|
29. |
What is the current syntax of rename() a file?(a) rename(current_file_name, new_file_name)(b) rename(new_file_name, current_file_name,)(c) rename(()(current_file_name, new_file_name))(d) none of the mentionedThe question was posed to me during an internship interview.My question is taken from Files topic in portion Regular Expressions and Files of Python |
Answer» RIGHT choice is (a) RENAME(current_file_name, new_file_name) The explanation is: This is the CORRECT syntax which has shown below. rename(current_file_name, new_file_name) |
|
30. |
What is the use of tell() method in python?(a) tells you the current position within the file(b) tells you the end position within the file(c) tells you the file is opened or not(d) none of the mentionedThis question was posed to me in unit test.This question is from Files in division Regular Expressions and Files of Python |
Answer» The correct CHOICE is (a) tells you the current position within the file |
|
31. |
The readlines() method returns ____________(a) str(b) a list of lines(c) a list of single characters(d) a list of integersI had been asked this question in a job interview.My question is based upon Files topic in section Regular Expressions and Files of Python |
Answer» Correct answer is (B) a list of lines |
|
32. |
To read the remaining lines of the file from a file object infile, we use ____________(a) infile.read(2)(b) infile.read()(c) infile.readline()(d) infile.readlines()The question was asked in quiz.I'd like to ask this question from Files in chapter Regular Expressions and Files of Python |
Answer» The CORRECT OPTION is (d) infile.readlines() |
|
33. |
To read the next line of the file from a file object infile, we use ____________(a) infile.read(2)(b) infile.read()(c) infile.readline()(d) infile.readlines()This question was addressed to me in my homework.This is a very interesting question from Files topic in section Regular Expressions and Files of Python |
Answer» CORRECT CHOICE is (c) infile.readline() Explanation: Execute in the SHELL to VERIFY. |
|
34. |
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()The question was asked during an online exam.Asked question is from Files in division Regular Expressions and Files of Python |
Answer» CORRECT choice is (B) infile.read() To EXPLAIN I WOULD say: read FUNCTION is used to read all the lines in a file. |
|
35. |
To read two characters from a file object infile, we use ____________(a) infile.read(2)(b) infile.read()(c) infile.readline()(d) infile.readlines()The question was asked by my college director while I was bunking the class.Question is taken from Files topic in chapter Regular Expressions and Files of Python |
Answer» RIGHT ANSWER is (a) infile.read(2) Explanation: Execute in the SHELL to verify. |
|
36. |
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 mentionedI had been asked this question by my school teacher while I was bunking the class.My question is based upon Files topic in chapter Regular Expressions and Files of Python |
Answer» CORRECT ANSWER is (d) All of the mentioned The explanation is: The program will THROW an ERROR. |
|
37. |
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”)This question was posed to me during an interview.My query is from Files topic in division Regular Expressions and Files of Python |
Answer» RIGHT ANSWER is (a) outfile = OPEN(“c:\\scores.txt”, “a”) The EXPLANATION is: a is used to indicate that data is to be APPENDED. |
|
38. |
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”)The question was posed to me in exam.This intriguing question originated from Files topic in section Regular Expressions and Files of Python |
Answer» The correct choice is (B) outfile = open(“c:\\scores.txt”, “W”) |
|
39. |
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”)This question was posed to me in an online quiz.Question is from Files in chapter Regular Expressions and Files of Python |
Answer» CORRECT option is (b) INFILE = OPEN(“c:\\scores.txt”, “r”) Best EXPLANATION: Execute help(open) to GET more details. |
|
40. |
Which of the following lines of code will not show a match?(a) >>> re.match(‘ab*’, ‘a’)(b) >>> re.match(‘ab*’, ‘ab’)(c) >>> re.match(‘ab*’, ‘abb’)(d) >>> re.match(‘ab*’, ‘ba’)This question was addressed to me in an international level competition.I would like to ask this question from Regular Expressions topic in section Regular Expressions and Files of Python |
Answer» The correct CHOICE is (d) >>> re.match(‘ab*’, ‘BA’) |
|
41. |
Which of the following functions does not accept any argument?(a) re.purge(b) re.compile(c) re.findall(d) re.matchI had been asked this question in an interview for job.My query is from Regular Expressions topic in portion Regular Expressions and Files of Python |
Answer» The CORRECT option is (a) re.purge |
|
42. |
Which of the following statements regarding the output of the function re.match is incorrect?(a) ‘pq*’ will match ‘pq’(b) ‘pq?’ matches ‘p’(c) ‘p{4}, q’ does not match ‘pppq’(d) ‘pq+’ matches ‘p’The question was posed to me in an online quiz.Question is taken from Regular Expressions topic in section Regular Expressions and Files of Python |
Answer» Right answer is (d) ‘pq+’ matches ‘p’ |
|
43. |
Which of the following functions returns a dictionary mapping group names to group numbers?(a) re.compile.group(b) re.compile.groupindex(c) re.compile.index(d) re.compile.indexgroupI had been asked this question in exam.The question is from Regular Expressions topic in section Regular Expressions and Files of Python |
Answer» Correct answer is (b) re.compile.groupindex |
|
44. |
Which of the codes shown below results in a match?(a) re.match(‘George(?=Washington)’, ‘George Washington’)(b) re.match(‘George(?=Washington)’, ‘George’)(c) re.match(‘George(?=Washington)’, ‘GeorgeWashington’)(d) re.match(‘George(?=Washington)’, ‘Georgewashington’)I had been asked this question in my homework.This intriguing question originated from Regular Expressions topic in chapter Regular Expressions and Files of Python |
Answer» Right option is (c) re.match(‘GEORGE(?=Washington)’, ‘GeorgeWashington’) |
|
45. |
Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?(a) (?:…)(b) (?=…)(c) (?!…)(d) (?#…)This question was addressed to me in homework.The query is from Regular Expressions in division Regular Expressions and Files of Python |
Answer» The CORRECT choice is (d) (?#…) |
|
46. |
The function of re.search is __________(a) Matches a pattern at the start of the string(b) Matches a pattern at the end of the string(c) Matches a pattern from any part of a string(d) Such a function does not existThe question was asked during a job interview.Query is from Regular Expressions topic in chapter Regular Expressions and Files of Python |
Answer» The correct OPTION is (C) Matches a pattern from any part of a string |
|
47. |
Which of the following functions results in case insensitive matching?(a) re.A(b) re.U(c) re.I(d) re.XI had been asked this question in exam.This interesting question is from Regular Expressions topic in chapter Regular Expressions and Files of Python |
Answer» The correct ANSWER is (c) re.I |
|
48. |
Which of the following functions clears the regular expression cache?(a) re.sub()(b) re.pos()(c) re.purge()(d) re.subn()This question was posed to me during a job interview.I'm obligated to ask this question of Regular Expressions in section Regular Expressions and Files of Python |
Answer» Right ANSWER is (C) re.purge() |
|
49. |
Choose the function whose output can be: .(a) >>> re.search(‘aaaa’, “alohaaaa”, 0)(b) >>> re.match(‘aaaa’, “alohaaaa”, 0)(c) >>> re.match(‘aaa’, “alohaaa”, 0)(d) >>> re.search(‘aaa’, “alohaaa”, 0)The question was asked in an internship interview.This key question is from Regular Expressions topic in section Regular Expressions and Files of Python |
Answer» The correct option is (a) >>> re.SEARCH(‘aaaa’, “alohaaaa”, 0) |
|
50. |
The expression a{5} will match _____________ characters with the previous regular expression.(a) 5 or less(b) exactly 5(c) 5 or more(d) exactly 4This question was posed to me in a national level competition.This interesting question is from Regular Expressions in division Regular Expressions and Files of Python |
Answer» The correct choice is (b) EXACTLY 5 |
|