Python Files MCQ: Python Files Multiple Choice Questions and Answers

Python Files MCQ with answers and explanations for placement tests and job interviews. This solved Python Files MCQ is useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our Python Files MCQ focuses on all areas of Python and its concept. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

We have already published a blog post that contains short questions on Python If you want you can also see this blog post “Python interview questions“.

 

There are several Python courses that you may have come across during your search for learning Python. Our team of experts has carefully analyzed some Python courses for you. You can check the courses, Trial of some courses is free.

 

Guideline of Python Files MCQ:

This Python Files MCQ is intended for checking your Python knowledge. It takes 40 minutes to pass the Python Data Types Quiz. If you don’t finish the Python Files MCQ within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on Python Data Types has features of randomization which feel you a new question set at every attempt.

In this Python Files MCQ, we have also implemented a feature that not allowed the user to see the next question or finish the quiz without attempting the current Python Files MCQ.

0 votes, 0 avg

You have 40 minutes to take the Python Files MCQs

Your time has been Over.


Python Files MCQ

Python MCQ

Python Files MCQ: Python Files Multiple Choice Questions and Answers

1 / 25

Which of the following statements are true?

2 / 25

To open a file c:\abc.txt for appending data, we use ____________

3 / 25

When writing to a CSV file using the .writerow() method of the csv.DictWriter object, what must each key in the input dict represent? Below is an example:

with open('test_file.csv', mode='w') as csv_file:

    writer = csv.DictWriter(
        csv_file, 
        fieldnames=['first_col', 'second_col']
    )
    writer.writeheader()

    # This input dictionary is what the question is referring
    # to and is not necessarily correct as shown.
    writer.writerow({'key1':'value1', 'key2':'value2'})

 

4 / 25

Using the same directory structure as before:

animals/
│
├── feline/  ← cwd
│   ├── lions.gif
│   └── tigers.gif
│
├── ursine/
│   └── bears.gif
│
└── animals.csv

Assuming that the cwd is in the feline folder, what is the relative path to the file lions.gif?

5 / 25

When iterating over an object returned from csv.reader(), what is returned with each iteration?

For example, given the following code block that assumes csv_reader is an object returned from csv.reader(), what would be printed to the console with each iteration?

for item in csv_reader:
    print(item)

 

6 / 25

To open a file c:\abc.txt for reading, we use _____________

7 / 25

Which of the following commands can be used to read the next line in a file using the file object "file"?

8 / 25

Whenever possible, what is the recommended way to ensure that a file object is properly closed after usage?

9 / 25

In separated value files such as .csv and .tsv, what does the first row in the file typically contain?

10 / 25

Which of the following functions can be used to check if a file “abc.txt” exists?

11 / 25

Given the file abc.txt, which of the following is the correct way to open the file for reading as a text file? Select all that apply.

12 / 25

Using the same directory structure as before:

animals/
│
├── feline/
│   ├── lions.gif
│   └── tigers.gif
│
├── ursine/
│   └── bears.gif
│
└── animals.csv

Assuming that the cwd is in the root folder where the directory animals resides, what is the absolute path to the file bears.gif?

13 / 25

By default, pandas uses 0-based indices for indexing rows. Which of the following is the correct way to import the CSV file hrdata.csv for reading and using the 'Name' column as the index row instead?

Below is the contents of hrdata.csv

Name,Hire Date,Salary,Sick Days remaining
Fred,10/10/10,10000,10

 

14 / 25

Whenever possible, what is the recommended way to ensure that a file object is properly closed after usage?

15 / 25

Using the same directory structure as before:

animals/
│
├── feline/  ← cwd
│   ├── lions.gif
│   └── tigers.gif
│
├── ursine/
│   └── bears.gif
│
└── animals.csv

Assuming that the cwd is in the feline folder, what is the relative path to the file bears.gif?

 

16 / 25

In regards to separated value files such as .csv and .tsv, what is the delimiter?

17 / 25

Given the file abc.png, which of the following is the correct way to open the file for reading as a buffered binary file? Select all that apply.

18 / 25

Which of the following commands can be used to read “3” number of characters from a file using the file object?

19 / 25

Which of the following is the correct way to open the CSV file hrdata.csv for reading using the pandas package? Assume that the pandas package has already been imported.

20 / 25

Which of the following command is used to open a file “c:\abc.txt” in write-mode only?

21 / 25

Assume you have a file object my_data which has properly opened a separated value file that uses the tab character (\t) as the delimiter.

What is the proper way to open the file using the Python csv module and assign it to the variable csv_reader?

Assume that csv has already been imported.

22 / 25

To read the entire remaining contents of the file as a string from a file object "file", we use ____________

23 / 25

Given the following directory structure:

animals/
│
├── feline/
│   ├── lions.gif
│   └── tigers.gif
│
├── ursine/
│   └── bears.gif
│
└── animals.csv

Assuming that the cwd is in the root folder where the animals directory resides, what is the relative path to the feline folder?

 

24 / 25

When reading a file using the file object, what method is best for reading the entire file into a single string?

25 / 25

Which of the following commands can be used to read the remaining lines in a file using the file object "file"?

Your score is

The average score is 0%

0%

Recommended Articles for you: