TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #22 · 19 јан.

Заметка начинающим, которые часто сталкиваются с подобной непоняткой. Ситуация следующая, есть список файлов: names = [ 'image.bmp', 'second.txt.bkp', 'data.db', '.config.cfg', 'file.ext.bkp' ] И мы хотим убрать у них окончание ".bkp". Не знаю зачем, пример довольно надуманный) Но суть он показывает, а это главное. Те, кто еще не очень знаком с библиотекой os.path или pathlib, вероятно решат обработать имена как строки. И тут вполне подойдет метод строки strip(). Что делает этот метод? Он отрезает указанные символы по обеим сторонам строки. Если ничего не указать, то убирает невидимые символы (пробелы, табуляции и переносы строк). В нашем случае будет выглядеть вот так: >>> name.strip('.bkp') То есть просим удалить строку '.bkp' по краям имени файла, если таковая есть. Можно применить аналогичный метод rstrip(), чтобы отрезать только справа, но для этого примера используем обычный. >>> for name in names: >>> print(name.strip('.bkp')) image.bm second.txt data.d config.cfg file.ext Хм, что-то не то с нашими именами! Что случилось??? Видим нежелательное переименование в именах, где и близко не было указанной строки '.bkp' А дело всё в том, что данный метод ищет не указанную строку, а указанные символы, и не важно в каком порядке. Для метода strip() строка '.bkp' это не паттерн для поискаа список символов. Потому он отрезал симовол 'p' от '.bmp' и удалил точку из файла '.config.cfg'. Как тогда правильно заменить именно паттерн? Для начинающего можно посоветовать метод строки replace(), который как раз использует для замены указанную строку целиком. В нашем примере заменим её на пустую строку. >>> for name in names: >>> print(name.replace('.bkp', '')) image.bmp second.txt data.db .config.cfg file.ext Уже лучше, но помните, это лишь пример про strip(). Для работы с именами файлов есть способы и более "правильные", дающие однозначно верный результат. Я взял файлы только в качестве примера. Даже replase() тут может сделать не то что ожидаем. Просто впредь будьте внимательны с этим strip(). #basic

Hashtags

Резултати

Пронајдени 17 слични објави

Пребарај: #demographics

当前筛选 #demographics清除筛选
Amazing Geography 🌍

@amazingeo · Post #15 · 10.08.2025 г., 00:12

🌍 In 1800, fewer than 1 billion people lived on Earth. Today, the world population has soared past 8 billion, with more than half living in urban areas like cities and large towns. ✨ #population⚡#urbanization⚡#demographics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Amazing Geography 🌍

@amazingeo · Post #211 · 10.09.2025 г., 13:12

🌍 By 2050, city dwellers are expected to make up nearly 70% of the global population. Urban areas are now growing twice as fast as rural regions, reshaping how billions of people live. ✨ #urbanization⚡#cities⚡#demographics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #344 · 07.10.2025 г., 18:31

🌍 More than 1 in 3 people alive today live in just two countries—China and India. Together, their populations make up over 2.7 billion people, shaping trends in language, culture, and the global economy. ✨ #population⚡#demographics⚡#Asia⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #605 · 31.01.2026 г., 20:31

🌍 In November 2022, the world’s population reached 8 billion for the first time, doubling in just 48 years since 1974—a record pace in human history for global population growth. ✨ #population⚡#demographics⚡#growth⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #494 · 04.12.2025 г., 20:31

🌍 In 2023, India gained over 13 million people—more than the total population of some countries. This rapid growth boosts its status as the planet’s most populous nation. ✨ #population⚡#demographics⚡#growth⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #264 · 19.09.2025 г., 09:12

🌍 In 2023, Ethiopia recorded the world’s highest annual natural population increase, adding nearly 2.7 million people in a single year—more than many countries’ entire populations. ✨ #population⚡#demographics⚡#growth⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

International News

@intnewsagency · Post #9345 · 22.04.2026 г., 15:27

Ukraine Considers Raising Retirement Age to 67 Facing a demographic crisis and labor shortages, Ukraine is considering raising the retirement age to 67. Currently, about 10.5 million pensioners equal the number of working-age citizens, straining the pension system. Experts warn the situation will worsen by 2040 due to an aging population. This discussion comes amid record population decline and restrictions on young Ukrainians leaving the country. #Ukraine#pension#demographics#crisis The main news of Russia and the world ishere.

Amazing Geography 🌍

@amazingeo · Post #305 · 27.09.2025 г., 20:31

🌍 Over one million people are added to the world population roughly every five days. The fastest-growing regions are now in parts of Africa, where birth rates remain among the highest globally. ✨ #demographics⚡#growth⚡#continents⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #592 · 25.01.2026 г., 12:31

🌍 In 2022, the number of international migrants reached an estimated 281 million—more than triple the figure from 1970—making up 3.6% of the world’s total population today. ✨ #migration⚡#demographics⚡#movement⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #38 · 12.08.2025 г., 20:12

🌍 India is now the world’s most populous country, with more people than any other nation. Its population surpassed 1.4 billion in 2023, highlighting rapid growth and demographic change. ✨ #India⚡#population⚡#demographics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

12
ПретходнаСтраница 1 од 2Следна