@profile_pictures_tm · Post #19133 · 27.01.2025 г., 16:52
#Universe💫 ✨✨
Hashtags
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
Пребарај: #universe
@profile_pictures_tm · Post #19133 · 27.01.2025 г., 16:52
#Universe💫 ✨✨
Hashtags
@astronomic · Post #3251 · 24.08.2023 г., 17:27
#Universe @Astronomic
Hashtags
@astronomic · Post #3127 · 19.03.2023 г., 06:28
#UNIVERSE This is so beautiful 😍 @Astronomic
Hashtags
@interesting_planet_facts · Post #1382 · 23.04.2026 г., 22:11
🌎 The coldest known place in the universe is the Boomerang Nebula, located about 5,000 light-years from Earth. Its temperature is just 1 kelvin, or –272°C, which is even colder than the background temperature of space. This nebula formed from rapidly expanding gas blown out by a dying star. ✨ #space⚡#universe⚡#astronomy 👉subscribe Interesting Planet 👉more Channels
Hashtags
@interesting_planet_facts · Post #680 · 03.09.2025 г., 13:22
🌎 The Boötes Void is an enormous empty region of space, spanning about 330 million light-years across. This cosmic void contains far fewer galaxies than expected, making it one of the largest known gaps in the observable universe. ✨ #space⚡#astronomy⚡#universe 👉subscribe Interesting Planet
Hashtags
@astronomic · Post #3211 · 27.06.2023 г., 06:48
#Space #Universe @astronomic
@testflightynoti · Post #38026 · 10.05.2026 г., 08:28
#Asteroid#Music#Universe Join the Asteroid - Music Universe beta on ✈️#TestFlight 🔗 Link: https://testflight.apple.com/join/MvMzHPZV Shared by Dimitri
@interesting_planet_facts · Post #626 · 25.08.2025 г., 13:22
🌎 At the edge of the observable universe, mysterious “dark flow” tugs galaxy clusters in the same direction, hinting at unseen forces or realms beyond our cosmic horizon. This puzzling movement can’t be explained by known gravity alone, sparking debate about what lies outside the visible universe. ✨ #space⚡#universe⚡#cosmology 👉subscribe Interesting Planet
Hashtags
@interesting_planet_facts · Post #1118 · 10.12.2025 г., 22:11
🌎 Scientists researching the mysteries of parallel worlds often reference "brane theory," which suggests our universe could be a 3D surface, or 'brane,' floating in higher-dimensional space. In this model, multiple branes—each a universe with its own laws—could exist, and gravity may leak between them, which physicists are testing with experiments at facilities like CERN. ✨ #physics⚡#universe⚡#dimensions 👉subscribe Interesting Planet 👉more Channels
Hashtags
@interesting_planet_facts · Post #780 · 19.09.2025 г., 13:22
🌎 Hidden in the vast cosmic darkness, rogue planets drift alone through space without orbiting any star. These “orphan worlds” form when gravitational forces eject young planets from their home systems. Some estimates suggest our galaxy may contain more rogue planets than stars. ✨ #universe⚡#astronomy⚡#exoplanets 👉subscribe Interesting Planet
Hashtags
@interesting_planet_facts · Post #1236 · 19.01.2026 г., 12:11
🌎 Mysterious dark matter makes up about 27% of the universe, but it does not emit or absorb light, making it invisible. Scientists detect dark matter only through its gravitational effects on galaxies and galaxy clusters. The leading candidates for dark matter particles are called WIMPs—Weakly Interacting Massive Particles. ✨ #space⚡#universe⚡#astrophysics 👉subscribe Interesting Planet 👉more Channels
Hashtags
@interesting_planet_facts · Post #654 · 30.08.2025 г., 00:22
🌎 An ancient mystery lingers at the center of our galaxy—a supermassive black hole called Sagittarius A*. Its powerful gravity bends space and time, hiding beyond a swirling cloud of stars and gas. This invisible giant shapes the Milky Way, anchoring everything around it with immense, unseen force. ✨ #space⚡#blackhole⚡#universe 👉subscribe Interesting Planet
Hashtags