What is the output of the following Python code snippet?
from datetime import datetime
print(datetime.strptime('2024-03-05', '%Y-%m-%d').year)
-
A
24
-
B
2024-03
-
C
2024
Correct answer
-
D
Error
6 views
Explanation
strptime parses a string into a datetime object using a format code.
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ