Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
46.
How can you read and print the lines that end with "!" from a file named "text.txt"?
Answer: Option
Explanation:
Using
endswith()
to filter and print lines ending with "!".
47.
What does the
os.path.getctime()
function return?
Answer: Option
Explanation:
os.path.getctime()
returns the creation time of a file.
48.
How can you write a list of strings to a file named "output.txt"?
Answer: Option
Explanation:
Using a context manager to open the file and writing a list of strings.
49.
How can you check if a file named "data.xml" is a valid XML file?
Answer: Option
Explanation:
Checking if a file has an XML extension to determine if it's a valid XML file.
50.
How can you read and print the lines containing both "Python" and "programming" from a file named "code.txt"?
Answer: Option
Explanation:
Using
in
to check for both "Python" and "programming" in each line.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers