1. Home
  2. Data Science
  3. Python
  4. What is the output of the following Python code snippet?

Added 25 Nov 2026

What is the output of the following Python code snippet?

from datetime import datetime
print(datetime.strptime('2024-03-05', '%Y-%m-%d').year)
  1. 24
  2. 2024-03
  3. 2024 Correct answer
  4. Error

Correct answer

C. 2024

5 views

MCQSEXAM

Explanation

strptime parses a string into a datetime object using a format code.

Reference

Asked in: Python Interview Standard Library

https://docs.python.org/3/library/index.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs