Python - Standard Library UsageWhich of the following is the correct syntax to open a file named 'log.txt' for reading in Python?Aopen('log.txt', 'w')Bopen('log.txt', 'a')Copen('log.txt', 'r')Dopen('log.txt', 'x')Check Answer
Step-by-Step SolutionSolution:Step 1: Identify the mode for readingThe mode 'r' is used to open a file for reading only.Step 2: Check other modes'w' is for writing (overwrites), 'a' is for appending, and 'x' is for creating a new file and writing. So only 'r' fits reading.Final Answer:open('log.txt', 'r') -> Option CQuick Check:Read mode = 'r' [OK]Quick Trick: Use 'r' mode to read files safely [OK]Common Mistakes:MISTAKESUsing 'w' instead of 'r'Confusing 'a' with read modeUsing 'x' which fails if file exists
Master "Standard Library Usage" in Python9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Python Quizzes Classes and Object Lifecycle - Accessing and modifying attributes - Quiz 3easy Classes and Object Lifecycle - Class attributes - Quiz 7medium Custom Exceptions - Adding custom attributes - Quiz 8hard Encapsulation and Data Protection - Property decorator usage - Quiz 12easy Exception Handling Fundamentals - Common exception types - Quiz 2easy Methods and Behavior Definition - Methods with parameters - Quiz 14medium Methods and Behavior Definition - Methods with parameters - Quiz 1easy Methods and Behavior Definition - Methods with parameters - Quiz 12easy Standard Library Usage - Environment variables usage - Quiz 3easy Structured Data Files - Dictionary-based CSV handling - Quiz 1easy