Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q13 of Q15
Python - Standard Library Usage
What will be the output of this code?
from datetime import date, timedelta
start = date(2024, 4, 25)
new_date = start + timedelta(days=10)
print(new_date)
A2024-05-05
B2024-04-15
C2024-04-25
DError: unsupported operand
Step-by-Step Solution
Solution:
  1. Step 1: Understand timedelta addition

    Adding timedelta(days=10) to April 25, 2024 adds 10 days.
  2. Step 2: Calculate new date

    April 25 + 10 days = May 5, 2024.
  3. Final Answer:

    2024-05-05 -> Option A
  4. Quick Check:

    25 April + 10 days = 5 May [OK]
Quick Trick: Add timedelta days to date to get new date [OK]
Common Mistakes:
MISTAKES
  • Subtracting days instead of adding
  • Confusing timedelta with datetime
  • Expecting string input for timedelta

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes