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

Резултати

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

Пребарај: #elephants

当前筛选 #elephants清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #484 · 02.08.2025 г., 03:22

🌎 Deep in the Congo Basin, the African rainforest elephant forges secret trails through dense jungle, creating “elephant highways” that other animals use. These hidden paths help shape entire forest ecosystems by opening routes for seed dispersal and wildlife movement. ✨ #rainforest⚡#elephants⚡#ecosystems 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1312 · 23.02.2026 г., 22:11

🌎 Elephants communicate using deep rumbles that travel through the ground as seismic vibrations. These low-frequency sounds allow herds to “hear” each other from several kilometers away, even when out of sight. ✨ #elephants⚡#communication⚡#animalbehavior 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #783 · 19.09.2025 г., 20:22

🌎 Elephants use infrasound—low-frequency sounds below human hearing—to communicate over distances of several kilometers. These vibrations travel through the ground and air, letting herds coordinate movements and warn of threats. Elephant infrasound calls can be detected up to 10 km away in open savanna. ✨ #elephants⚡#communication⚡#animalintelligence 👉subscribe Interesting Planet ​

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40697 · 24.02.2026 г., 09:20

Elephants can “listen” with their feet. Their foot pads have special nerve receptors that detect ground vibrations, including very low-frequency infrasound. Vibrations from other elephants’ rumbles or footsteps travel through the ground. Signals move through their bodies to the brain. Vibrations can also reach the inner ear through bone conduction. This helps elephants communicate over long distances and sense distant movement. 🐘🌍👣🔊 [Read more] @googlefactss #Elephants#AnimalFacts#Wildlife#Nature#Science#DidYouKnow

💛The Power of a Mother’s Love In Kruger National Park, South Africa, an elephant cow rescued her calf as it was being swept away by a powerful current. 📹 The touching footage comes from an area affected by severe flooding. The natural disaster caused serious damage to the park’s infrastructure: people were evacuated, and some animals had to fend for themselves. According to park officials, most animals moved to higher ground in advance — but not all managed to escape the danger. 🔗Video: https://t.me/aifonline/177687 #SouthAfrica#Wildlife#Nature#Elephants#MothersLove#KrugerNationalPark

🐘🍊Стадо слонов-воришек в провинции Лимпопо, ЮАР, полакомилось апельсинами, которые перевозил сломавшийся в дороге грузовик. _________________________ 🐘🍊 A herd of opportunistic elephants in Limpopo, South Africa, helped themselves to a feast of oranges transported by a truck that had broken on the road. 📹https://www.youtube.com/watch?v=-i5_brrf1cc #ЮАР#Слоны#Природа#Африка#Животные #SouthAfrica#Elephants#Wildlife#Nature#Africa

🇿🇦Tembe Elephant Park🐘 The park was established in the north-eastern part of South Africa in 1983 to protect elephants migrating between South Africa and Mozambique. 🌍 It opened to visitors in 1991 and is now home to about 250 of the largest elephants in the world. 🏞 If you’re into safaris, you can also spot the rest of the Big Five — 🦁 lions, 🐆 leopards, 🦏 rhinos, and 🐃 buffalo. 🎥 Live video: 👉https://www.youtube.com/watch?v=VUJbDTIYlM4 #SouthAfrica#Nature#Safari#BigFive#Elephants#Tembe#Wildlife#Travel#Africa

🐘Слоны — отличные пловцы, и это занятие им очень нравится! Они способны преодолевать расстояния до 50 км. А ещё они умеют нырять — хобот служит им дыхательной трубкой для «подводного плавания». 🤿 #Слоны#Животные#Природа#ЮАР#ИнтересныеФакты ___________________ 🐘Elephants are excellent swimmers — and they love it! They can cover distances of up to 50 km (30 miles). They also dive skillfully, using their trunks as natural snorkels. 🤿 #Elephants#Wildlife#Nature#SouthAfrica#FunFacts 🎥https://t.me/AfroPouchkine/1459