Тип строки в 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
😄Draw
➖➖➖➖➖➖
🔘 Drawis commonly used as a verb that means creating a picture or image
🔜My cousin drew our family using different coloured pencils.
🔜My daughter has just learned to draw!
🔘We can also use the verb ‘draw’ to mean attracting attention - someone wanting to look at something.
🔜The amazing singer drew a huge audience.
🔜A World Cup game is guaranteed to draw a large number of viewers!
🔘 Drawas a noun can also describe competition results that are equal.
🔜The football match ended in a draw – it was 1:1.
🔜This boxer has never lost a fight - he has six wins and a draw.
#Draw👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
⚠️ The project was suspended. Funds may be at risk.
🌟Starverse — Telegram Stars Farming and Everyday Giveaways
Earning stars has never been so exciting! #Starverse is a game where your tickets turn into real money. A project from the TgLab team, creators of the popular TON Dating mini app.
⏳Farming
Every hour you can turn on farming and take a part of the total income of the players.
Half of all revenue goes to farmers — the more tickets you have, the bigger the drop.
Farm, reinvest and invite friends — you'll get 15% of their purchases.
💰Golden Ticket
Every day at 9:00 UTC a winner is randomly selected and receives 15% of all purchases made during the day.
How to participate:
- farm at least 3 hours a day
- buy at least one ticket on the day of the drawing
💰Easy Withdraw
Got Stars? You can immediately transfer them to your Telegram account or convert to $USDT without delays.
⭐️Start farming now!
#stars#farming#draw#web3