MCQ Single Best Answer Difficult

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

ID: #20270 Create Objects in Python 185 views
Question Info
#20270Q ID
DifficultDifficulty
Create Objects in PythonTopic

Choose the Best Option

Click any option to instantly check if you're 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: Option 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

Challenge a friend or share with your study group.