1.

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()

To explain: With the writeline FUNCTION you can WRITE a list of strings to a file

fh = OPEN(“hello.txt”, “w”)

lines_of_text = [“a line of TEXT”, “another line of text”, “a third line”]

fh.writelines(lines_of_text).



Discussion

No Comment Found

Related InterviewSolutions