Computer Science
Assertion. The file modes "r", "w", "a" also reveal the type of file these are being used with.
Reason. The binary file modes have 'b' suffix with regular file modes.
Python File Handling
1 Like
Answer
(a)
Both Assertion and Reason are true and Reason is the correct explanation of Assertion.
Explanation
When we see file modes like "r", "w", or "a" being used in code, it often implies operations on text files. These modes are commonly associated with reading from, writing to, or appending text data in files. In Python, binary file modes are distinguished from text file modes by appending 'b' suffix to the regular file modes. For example, 'rb', 'wb', 'ab'. The presence of the 'b' suffix indicates that the file is being opened in binary mode, suggesting operations involving binary data.
Answered By
2 Likes
Related Questions
Assertion. Python is said to have broadly two types of files - binary and text files, even when there are CSV and TSV files also.
Reason. The CSV and TSV are types of delimited text files only where the delimiters are comma and tab respectively.
Assertion. The file modes "r", "w", "a" work with text files, CSV files and TSV files alike.
Reason. The CSV and TSV are types of delimited text files only.
Assertion. 'Pickling' is the process whereby a Python object hierarchy is converted into a byte-stream.
Reason. A binary file works with byte-streams.
Assertion. 'Pickling' is the process whereby a Python object hierarchy is converted into a byte-stream.
Reason. Pickling process is used to work with binary files as a binary file works with byte-streams.