PCAP Standard Library and Built-ins 1 — Questions and Answers
Question 1: Which module provides tools for working with dates and times in Python?
- time
- clock
- datetime (Correct answer)
- calendar
Correct answer: datetime
The `datetime` module provides classes for manipulating dates and times.
Question 2: What does `random.randint(1, 10)` return?
- A float between 1 and 10
- A random integer from 1 to 9
- A random integer from 1 to 10 inclusive (Correct answer)
- A random float from 0 to 1
Correct answer: A random integer from 1 to 10 inclusive
`random.randint(a, b)` returns a random integer N such that a <= N <= b (both endpoints included).
Question 3: Which function from the `os` module returns the current working directory?
- os.pwd()
- os.getcwd() (Correct answer)
- os.cwd()
- os.getdir()
Correct answer: os.getcwd()
`os.getcwd()` returns the current working directory as a string.
Question 4: What does `math.floor(3.9)` return?
- 4
- 3 (Correct answer)
- 3.9
- 4.0
Correct answer: 3
`math.floor()` returns the largest integer less than or equal to the given number.
Question 5: Which built-in function returns the number of items in a container?
- size()
- count()
- length()
- len() (Correct answer)
Correct answer: len()
`len()` returns the number of items in an object such as a list, string, or dictionary.
Question 6: What does `isinstance(42, int)` return?
- False
- True (Correct answer)
- 42
- int
Correct answer: True
`isinstance(42, int)` returns True because 42 is an instance of the `int` class.
Which module provides tools for working with dates and times in Python?