Тип строки в Python имеет очень много удобных методов. Сегодня пост про два таких метода которые чаще всего используются "однобоко". Это методы startswith() и endswith()
Самый обычный сценарий использования — проверка, начинается ли строка с указанной подстроки?
>>> "some_string".startswith("some")
True
И аналогичная ситуация с зеркальным вариантом этой функции, проверка совпадения с конца
>>> "some_string".endswith("some")
False
Так они используются в большинстве случаев что я видел. Но у этих функций есть еще два варианта использования.
🔸Сравнение нескольких подстрок
Для проверки нескольких подстрок в одной строке обычно вызывают эти функции несколько раз. Но на самом деле достаточно передать кортеж со всеми строками один раз. Если будет хоть одно совпадение то функция вернёт True.
>>>"my_image.png".endswith(("jpg", "png", "exr"))
True
🔸Диапазон поиска
Вторым аргументом можно передать индекс символа с которого следует начать сравнение, а третий аргумент это индекс последнего символа.
>>> ".filename.ext".startswith("file", 1)
True
>>> "file_###.ext".endswith('#', 0, -4)
True
Индексы можно указать отрицательными, что означает отсчёт с конца.
#trics#basic
Scientists found a new drug, SW033291, that protects the brain’s blood barrier by blocking an enzyme called 15-PGDH. This stops brain damage and memory loss in mice with Alzheimer’s and brain injuries. Unlike other drugs, it does not remove amyloid protein but still keeps the brain safe and working well. The drug worked even when given a day after injury.🧠💊
[Source]
@googlefactss
#Alzheimers#BrainHealth#Memory#Science
lethonomia (n)
pronunciation: leh – tho – NO – mee – uh
language: English
definition: the inability to recall someone’s name
sentence: It’s very embarrassing to be stricken with acute lethonomia when I have to make introductions at a party. 🧠🗣️
[Source]
@googlefactss#Lethonomia#Memory#LanguageDisorders#BrainHealth#CommunicationChallenges
Learning another language may slow brain aging, according to a huge new study. Multilingual people show less cognitive decline compared to those who speak only one language. The study suggests that speaking multiple languages helps keep brain networks active, especially those responsible for memory and attention, protecting the brain from aging effects.
🧠🌍💬
[Read more]
@googlefactss
#BrainHealth#Multilingual#CognitiveScience#Learning#HealthyAging
Some studies found that watching a lot of (internet)pornography can change the brain. Brain scans showed stronger links in areas that control emotions and decisions. People who watch often feel more pleasure but have less self-control. After watching, their thinking and attention get worse. Their facial expressions also show less emotion, like surprise or disgust, even if they say they enjoyed it. These changes are similar to drug addiction. Repeating this behavior can make emotional responses dull and reduce mental sharpness.
More research is needed, but finding people who never watched porn for studies is very difficult to impossible..
🧠📉
[Read more1]
[Read more2]
[Read more3]
[How to stop watching]
@googlefactss
#BrainHealth#Addiction#Pornography#porn#MentalHealth#Neuroscience
👮♂🚫Warning: Even though this post and the following poll are sexual in nature. Rules still apply. Be respectful or face the consequences..