Тип строки в 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
Mount Augustus in the Australian Outback is the largest rock on earth standing at approximately 717 meters (2,352 feet) high above the surrounding plains and can be seen from almost 100 miles away.
@googlefactss#geography
📍 What is the official language of the world’s largest island?
A) Malagasy
B) Greenlandic
C) English
D) Malay
Take the quiz below to see if you are correct
@languagetrivia#guess_the_language#geography
Gibraltar is a small territory located on the southern coast of the Iberian Peninsula, on the Mediterranean Sea. It is bordered by Spain to the north and sits at the entrance of the Strait of Gibraltar, which separates Europe from Africa. Known for its iconic Rock of Gibraltar, this territory has a unique geographic and cultural identity.
What is the official language of Gibraltar?
• A) Spanish
• B) English
• C) Andalusian Arabic
• D) Portuguese
Press ❤️
Follow @languagetrivia for more fun facts!
#geography#guess_the_language
The Salzkammergut is a region in Austria, mostly frequented for relaxation vacation, hiking and climbimg.
It stretches from the city of Salzburg eastwards to the Dachstein Mountains.
The historic city of Hallstatt is located in the Salzkammergut, giving name to the Hallstatt culture, the predominant Western and Central European culture of the late Bronze Age from the 12th to 8th centuries BC and early Iron Age from the 8th to 6th centuries BC.
#geography#history
@EuropeanTribalism
What is one of the two official languages of Macau, a region of China often referred to as the 'Las Vegas of the East'?
🧠 Join @languagetrivia for more fascinating questions
#guess_the_language#image#geography
Check out the correct answer in the comment
🌎 Along the India-Bangladesh border, a cluster of over 160 tiny enclaves once existed, creating a patchwork of territories within territories. Before a 2015 land swap, some villages belonged to India but were completely surrounded by Bangladesh, and vice versa, forming the world’s most complex international border tangle. ✨
#borders⚡#geography⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Baarle-Hertog and Baarle-Nassau, two towns in Belgium and the Netherlands, form one of the world’s most complex borders, with 26 separate enclaves and counter-enclaves interlocking like a puzzle. Some houses are split between countries, with the nationality determined by the location of the front door. ✨
#geography⚡#borders⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 The border between India and Bangladesh features over 160 enclaves and counter-enclaves—small pockets of land belonging to one country inside the other. Before a 2015 land swap, Dahala Khagrabari was the world’s only third-order enclave: an Indian village inside a Bangladeshi enclave, within an Indian enclave, inside Bangladesh. ✨
#borders⚡#geography⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Few borders are stranger than the Haskell Free Library and Opera House, built in 1904 directly on the US-Canada line. The building straddles Derby Line, Vermont, and Stanstead, Quebec, with a black line on the floor marking the international boundary. Its reading room is in the US, but most books are in Canada. ✨
#borders⚡#geography⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Strange borders divide the island of Cyprus: the capital, Nicosia, is split by the "Green Line," a UN-controlled buffer zone between Greek and Turkish Cypriot sectors. This boundary cuts through streets and buildings, creating the world’s last divided capital city. ✨
#borders⚡#geography⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 The divided town of Baarle straddles the border between Belgium and the Netherlands in a tangled patchwork of enclaves. Some houses are split by the boundary, so front doors determine which country's laws apply. This border complexity results from medieval land deals, with 22 Belgian and 8 Dutch enclaves in total. ✨
#borders⚡#geography⚡#history
👉subscribe Interesting Planet
👉more Channels