Тип строки в 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
🚀BIG ANNOUNCEMENT!
🚀
Bitcoin💸 just achieved a monumental milestone, breaking the 💵1 trillion market cap! 🎉📈 With the continuous surge in ATH🔝 (All-Time High) values every day, we can't help but capitalize on this golden opportunity.
📆 SAVE THE DATE: THIS SUNDAY
⌛️Time : 17:00 PM (GMT)
🚀 Pump Target: At least 700%
💰Duration: The pump is expected to last for days.
This isn't just a pump; it's a chance to ride the wave of success in the booming crypto market.
Turn on your notifications and join us on Sunday for an epic pump that could bring massive profits.
Let's make this one for the record books! 💸#BitcoinPump#CryptoSuccess
Got any Questions? @RobertMillercrypto
🔥 Mastercard, Citigroup, and JPMorgan Chase join forces to pilot shared ledger technology for Tokenized Assets settlement processes, with the goal of enhancing speed and security in cross-border transactions. This collaboration could transform the financial sector by enabling diverse asset types to settle on a unified platform.⭐️🌐
#Cryptoassets
#Cryptosuccess
#Blockchainrevolution
🎉SLEX Exchange HITS Top-50 on CoinPaprika! 🚀
💫SLEX Exchange made it into the Top-50 among over 300 cryptocurrency exchanges on CoinPaprika! This achievement highlights our dedication to providing top-notch trading services and robust security.
🤝Thank you to SLEX community for your trust and support. This achievement is as much yours as it is ours!❤️
🔗Check out our ranking: SLEX on CoinPaprika
🦾Come aboard SLEX - wheee crypto and commodity trading meet innovative features. Grow and profit with us! ☄️
#SLEX#Top50#CoinPaprika#CryptoSuccess
Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter
🚨Crypto Trading Guide for Beginners🚨
Ready to master crypto trading? Join Ekta Mourya from FXStreet as she breaks down how to stop gambling and start building wealth with a structured plan! 💥
Key Insights:
- Stop guessing, understand market cycles 📉
- Avoid 3 common mistakes beginners make ❌
- Use the Crypto Fear & Greed Index to your advantage 🤑
- Top-down analysis with simple tools like RSI & Moving Averages 📊
Start trading like a pro today.
Watch now! 👉https://www.youtube.com/watch?v=R8aAPHvHiKU
#CryptoTradingGuide#BitcoinForBeginners#FXStreet#CryptoSuccess#SmartMoneyConcepts
🚨Crypto Trading Guide for Beginners🚨
Ready to master crypto trading? Join Ekta Mourya from FXStreet as she breaks down how to stop gambling and start building wealth with a structured plan! 💥
Key Insights:
- Stop guessing, understand market cycles 📉
- Avoid 3 common mistakes beginners make ❌
- Use the Crypto Fear & Greed Index to your advantage 🤑
- Top-down analysis with simple tools like RSI & Moving Averages 📊
Start trading like a pro today.
Watch now! 👉https://www.youtube.com/watch?v=R8aAPHvHiKU
#CryptoTradingGuide#BitcoinForBeginners#FXStreet#CryptoSuccess#SmartMoneyConcepts