MCQ Practice Single Best Answer Topic: Create Objects in Python

Q Which of the following expression can be used to check if the file 'C:\Sample.txt' exists and is also a regular file?

Question ID
#20270
Subchapter
Create Objects in Python
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A os.path.isFile("C:\Sample.txt")
  • B os.isFile("C:\Sample.txt")
  • C os.path.isfile("C:\Sample.txt")
  • D os.path.exists("C:\Sample.txt")
Correct Answer: C

Explanation

The correct expression to check if the file 'C:\Sample.txt' exists and is also a regular file is:


os.path.isfile("C:\Sample.txt")

So, the correct answer is: os.path.isfile("C:\Sample.txt")

Share This Question

Share this MCQ with your friends or study group.