Logo
TGCATALOG
Catalog Collections Blog
Code on a Napkin - Python coding

Code on a Napkin - Python coding

Channel about programming in Python and other languages. Simple explanations and codes.

No ratings
317
26.10.2026
317
26.10.2026
No ratings
317
26.10.2026
Safe redirect via bot
О канале

Channel about programming in Python and other languages. Simple explanations and codes.

Подписчиков 2,345
Тематика Technology
Язык English
Ссылка t.me/napkincode

We also recommend

Kekaton AI | Voiceover and voice clone
Kekaton AI | Voiceover and voice clone
Bot

AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.

Description

Resource for those interested in programming. Focus on Python, but covers other topics as well. Simple examples and breakdowns.

Latest posts

Code on a Napkin - Python coding
Code on a Napkin - Python coding
🔒Открыть пост
и посмотреть медиа
Знаете ли вы, почему обрезка строки может удалить больше, чем ожидается? Аргумент strip() задает набор символов для удаления с краев строки. Метод идет с начала и конца и удаляет каждый символ, который входит в этот набор, пока не встретит другой. Поэтому при .strip(".com") по краям будут удаляться любые последовательности из ., c, o и m – в любом порядке и количестве. def domain_name(host): return host.strip(".com") print(domain_name("example.com")) # example print(domain_name("moscow.com")) # scow На первом хосте решение выглядит рабочим: справа отрезаются m, o, c и .. А слева стоит e, и так как ее в наборе нет – обрезка не начинается. На втором – слева стоят m и o, оба из набора, и оба отпадают, так что от moscow остается scow. def basename(filename): return filename.rstrip(".txt") print(basename("notes.txt")) # notes print(basename("report.txt")) # repor Односторонний rstrip от этого не спасает: он доходит справа до t, x, t, ., а следующая буква – t из слова report, тоже входит в набор. Так что имя файла укорачивается на букву, и дальше в код уходит repor. def domain_name(host): return host.strip(".com") def domain_name_fixed(host): return host.removesuffix(".com") print(domain_name("mom.com")) # пустая строка print(domain_name_fixed("mom.com")) # mom В mom.com каждый символ входит в набор, поэтому strip() удаляет строку целиком. А removesuffix и removeprefix, доступные с Python 3.9, работают с целой подстрокой: при совпадении удаляют ее целиком, при отсутствии совпадения возвращают исходную строку. strip() создан для обрезки пробелов и мусора по краям, так что на длинных аргументах он ведет себя как фильтр символов. Чтобы отрезать известный префикс или суффикс лучше импользовать removeprefix и removesuffix. Код на салфетке x Кусочки кода
Code on a Napkin - Python coding
FAQ

Open Code on a Napkin - Python coding in Telegram and press the Start button. No separate registration is required.

Yes. The service is designed to be straightforward: open the resource, follow the on-screen instructions and start using it.

No. You can use Code on a Napkin - Python coding directly in Telegram unless the resource description says otherwise.

Access depends on the resource. Check the current information in Telegram after opening Code on a Napkin - Python coding.

The exact features depend on the resource. Open Code on a Napkin - Python coding to see its current functions, content and access conditions.
Subscriber dynamics
+-0.5% last 30 days
Current
2,345
Month ago
2,356
Average growth
+0 / day
Updated
1 day ago

Reviews for channel Code on a Napkin - Python coding

Log in to leave a review

Only registered users can share their opinion.

No reviews yet

Be the first to share your impression of this resource!

Similar resources

Loading
Switch to Light Theme
Home Catalog Collections Blog Login