Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Timezone Examples | Timezones and Daylight Savings Time (DST)
Dealing with Dates and Times in Python

book
Timezone Examples

In the previous chapter, you saw one timezone: America/Edmonton. But the total number of even common timezones is quite big: more than 400! But you can see, that timezone by default contain continent name and city. So, we can explore the variety of timezones across the specific continent.

Since .all_timezones and common_timezones methods return lists, we can easily iterate over them. For example, using list comprehension, we can easily count the number of timezones containing 'America'.

# Load library
import pytz

# Count number of american timezones using list comprehension
american_timezones = len([x for x in pytz.common_timezones if 'America' in x])
print(f"There are {american_timezones} american timezones available in pytz.common_timesones.")
123456
# Load library import pytz # Count number of american timezones using list comprehension american_timezones = len([x for x in pytz.common_timezones if 'America' in x]) print(f"There are {american_timezones} american timezones available in pytz.common_timesones.")
copy
Завдання

Swipe to start coding

Iterate over .common_timezones and print only timezones containing Europe.

Рішення

# Load library
import pytz

# Iterate over .common_timezones
for i in pytz.common_timezones :
# Check if string contains 'Europe'
if 'Europe' in i:
# If yes, print its name
print(i)

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
# Load library
import pytz

# Iterate over .common_timezones
for i in pytz.___ :
# Check if string contains 'Europe'
if '___' ___ i:
# If yes, print its name
print(i)

Запитати АІ

expand
ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt