0
0
Pythonprogramming~5 mins

File modes and access types in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the file mode 'r' mean in Python?
The mode 'r' opens a file for reading only. The file must exist, or Python will raise an error.
Click to reveal answer
beginner
What happens if you open a file with mode 'w'?
The mode 'w' opens a file for writing. If the file exists, it will be erased (emptied). If it doesn't exist, a new file is created.
Click to reveal answer
intermediate
Explain the difference between 'a' and 'w' file modes.
Mode 'a' opens a file for appending, which means new data is added at the end without deleting existing content. Mode 'w' erases the file content before writing.
Click to reveal answer
beginner
What does the 'b' in file modes like 'rb' or 'wb' stand for?
The 'b' stands for binary mode. It means the file is opened in binary format, which is used for non-text files like images or videos.
Click to reveal answer
intermediate
What is the purpose of the '+' symbol in file modes like 'r+' or 'w+'?
The '+' symbol means the file is opened for both reading and writing.
Click to reveal answer
Which file mode opens a file for reading and writing without truncating it?
A'a'
B'w'
C'r+'
D'wb'
What happens if you open a non-existing file with mode 'r'?
ARaises an error
BAppends to the file
CCreates a new empty file
DReads an empty file
Which mode should you use to add data to the end of an existing file without deleting its content?
A'a'
B'w'
C'r'
D'rb'
What does the 'b' in 'rb' mode indicate?
ABuffered mode
BBinary mode
CBackup mode
DBasic mode
If you want to read and write a file and also create it if it doesn't exist, which mode is best?
A'r+'
B'rb'
C'w+'
D'a+'
Describe the main file modes in Python and when to use each.
Think about whether you want to read, write, add, or work with binary files.
You got /5 concepts.
    Explain what happens when you open a file in 'w' mode versus 'a' mode.
    Consider if the existing content stays or is removed.
    You got /3 concepts.