MCQOPTIONS
Saved Bookmarks
This section includes 7 Mcqs, each offering curated multiple-choice questions to sharpen your Python knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
The readlines() method returns ____________ |
| A. | str |
| B. | a list of lines |
| C. | a list of single characters |
| D. | a list of integers |
| Answer» C. a list of single characters | |
| 2. |
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() |
| Answer» E. | |
| 3. |
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() |
| Answer» D. infile.readlines() | |
| 4. |
To read two characters from a file object infile, we use ____________ |
| A. | infile.read(2) |
| B. | infile.read() |
| C. | infile.readline() |
| D. | infile.readlines() |
| Answer» B. infile.read() | |
| 5. |
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 ) |
| Answer» B. outfile = open( c: scores.txt , rw ) | |
| 6. |
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 ) |
| Answer» C. outfile = open(file = c: scores.txt , w ) | |
| 7. |
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 ) |
| Answer» C. infile = open(file = c: scores.txt , r ) | |