हिंदी

Write a try .... except statement that attempts to open a file for reading and catches the exception thrown when the file does not exist.

Advertisements
Advertisements

प्रश्न

Write a try .... except statement that attempts to open a file for reading and catches the exception thrown when the file does not exist.

कोड लेखन
Advertisements

उत्तर

try:
    file = open("data.txt", "r")
except FileNotFoundError:
    print("File does not exist.")
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Data File Handling - EXERCISE [पृष्ठ १४५]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 7 Data File Handling
EXERCISE | Q 3. | पृष्ठ १४५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×