Which of the following is the main reason to use standard library modules in Python?
Think about why you would want to reuse code instead of writing everything from scratch.
Standard library modules contain ready-made, tested functions and classes. Using them saves time and reduces bugs.
What is the output of this Python code?
import math print(math.sqrt(16))
Recall what the sqrt function does in the math module.
The sqrt function returns the square root of a number. The square root of 16 is 4.0.
What will this code print?
from datetime import datetime now = datetime.now() print(now.year)
Look at what now.year accesses from the datetime object.
The now() method returns the current date and time. Accessing year gives the current year as an integer.
Which of these is NOT a benefit of using Python's standard library modules?
Think about performance versus reliability and convenience.
While standard library modules are reliable and convenient, they do not always guarantee faster performance than custom code.
You want to read a text file line by line in Python. Which standard library module and function is the best choice?
Think about which module handles file operations.
The open() function is built-in and used to open files for reading or writing. Other modules do not handle file reading.