DEV Community

Vladimir Ignatev
Vladimir Ignatev

Posted on • Updated on

🤔 Python Quiz: Traveling Time Zones in Python 🕔

The topic for todays quiz is "Handling Time Zones in Python" covered by PEP 431 and PEP 495. These PEPs discuss improvements in timezone support in Python's datetime module, making it a relevant and somewhat challenging topic for beginners.

Follow me to learn 🐍 Python in 5-minute a day fun quizzes!

Quiz

Which code sample correctly handles time zones in Python?

Sample 1

from datetime import datetime, timezone

utc_time = datetime(2023, 12, 3, 10, 0, 0, tzinfo=timezone.utc)
local_time = utc_time.astimezone()
print(local_time)
Enter fullscreen mode Exit fullscreen mode

Sample 2

from datetime import datetime

local_time = datetime(2023, 12, 3, 10, 0, 0)
utc_time = local_time.astimezone("UTC")
print(utc_time)
Enter fullscreen mode Exit fullscreen mode

Post your answer in the comments – is it 0 for the first sample or 1 for the second! As usual, the correct answer will be explained in a comment.

Top comments (0)