🧘 Zen of Python¶
Філософія мови Python¶
Python — це не просто мова програмування.
Вона має власну філософію дизайну коду, яка називається Zen of Python.
🐍 Як побачити Zen of Python¶
Відкрийте Python interpreter:
The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!---
# 🇺🇦 Переклад і пояснення
## ✅ Beautiful is better than ugly
Код повинен бути зрозумілим і акуратним.
Python заохочує читабельність.
---
## ✅ Explicit is better than implicit
Явний код кращий за приховану магію.
```python
# добре
total = price * quantity
# погано
do_magic()
✅ Simple is better than complex¶
Рішення має бути максимально простим.
✅ Complex is better than complicated¶
Іноді складність неминуча, але код не повинен бути заплутаним.
✅ Flat is better than nested¶
Менше вкладеності → легше читати.
✅ Readability counts¶
Код читають частіше, ніж пишуть.
✅ Errors should never pass silently¶
Помилки потрібно бачити.
✅ In the face of ambiguity, refuse the temptation to guess¶
Python не намагається "вгадувати".
Краще явна помилка.
✅ One obvious way to do it¶
У Python зазвичай є один рекомендований спосіб.
Це протилежність Perl:
"There is more than one way to do it"
✅ Now is better than never¶
Працююче рішення краще ідеального плану.
✅ If implementation is hard to explain — it's a bad idea¶
Якщо код складно пояснити — він, ймовірно, неправильний.
✅ Namespaces are one honking great idea¶
Простори імен — ключова ідея Python.
Саме тому існують:
- modules
- packages
- virtual environments
🧠 Історія створення¶
Zen of Python був написаний у 1999 році розробником Python Tim Peters.
У 2001 році його додали у Python як приховану
пасхалку — модуль this.
🥚 Пасхалка №1 — шифрування¶
Текст Zen у модулі this
зашифрований за допомогою:
Python розшифровує його під час імпорту.
🥚 Пасхалка №2 — Dutch joke¶
Жарт про творця Python — Guido van Rossum, який є голландцем.
🥚 Пасхалка №3 — import antigravity¶
Спробуйте:
🙂
🧠 Чому Zen of Python важливий¶
Python навчає не тільки синтаксису, а мисленню програміста.
Zen визначає:
- стиль коду
- архітектуру
- дизайн API
- культуру Python community
✅ Головна ідея¶
Python — це мова, де:
Код пишеться для людей, а не тільки для комп’ютера.