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

TGINSIGHT SIMILAR POSTS

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

Изворен канал @pythonotes · Post #32 · 7 фев.

Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять: from timeit import timeit def t1(): # складываем 10 строк через + из переменной t = 'text' for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t2(): # склеиваем список строк через метод join arr = ['text'] * 10 for _ in range(1000): s = ''.join(arr) def t3(): # складываем через + но не из переменной а непосредственно инлайн объекты for _ in range(1000): s = 'text' + 'text' + 'text' + ... # всего 10 раз Теперь каждую строку склейки запустим по 10М раз >>> timeit(t1, number=10000) 0.21951690399964718 >>> timeit(t2, number=10000) 1.4978306379998685 >>> timeit(t3, number=10000) 0.2213820789993406 Хм, а нам говорили что через "+" это плохо и медленно ))) 😁 Тут стоит учитывать, что речь идёт о склейке множества длинных строк. Давайте изменим условия: def t4(): t = 'text'*100 for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t5(): arr = ['text'*100] * 10 for _ in range(1000): s = ''.join(arr) def t6(): for _ in range(1000): s = 'text'*100 + 'text'*100 + ... # всего 10 раз >>> timeit(t4, number=10000) 12.795130728000004 >>> timeit(t5, number=10000) 2.642637542999182 >>> timeit(t6, number=10000) 0.2184546610005782 Вот, уже другой разговор, сразу видна разница, в среднем в 6 раз. Но погодите, почему последний тест t6() по скорости такой же как и t3()? Ведь строки теперь в 100 раз длиннее! Это вопросы оптимизации кода, какие простые изменения ускоряют или замедляют выполнение программы. Мы столкнулись с примером обхода обращения к переменной. Например, именно так работает директива #define в С++, во время компиляции подставляя значение переменной вместо ссылки на неё. В Python это тоже работает, но часто ли вы сможете встретить такой способ работы со строками? К сожалению, способ почти только теоретический. В целом, тесты показали то, что мы хотели. Делаем выводы самостоятельно. Полный листинг 🌍 #tricks

Резултати

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

Пребарај: #insects

当前筛选 #insects清除筛选
Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40801 · 15.03.2026 г., 15:03

The praying mantis is the only insect that can turn its head rotating it up to 180 degrees due to a flexible joint between the head and prothorax. This unique, adaptation allows them to track prey and monitor surroundings without moving their bodies. @googlefactss#insects

Hashtags

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #39916 · 10.10.2025 г., 10:50

A tarantula hawk wasp finds and stings a tarantula then carries the paralyzed spider to its lair, where it lays a single egg on the spider before burying it alive. Once the egg hatches, the larva eats the inside of the still-living spider, being careful to avoid vital organs until last. @googlefactss#insects

Hashtags

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40524 · 11.01.2026 г., 15:05

Dragonfly nymphs (larvae) breathe and move using their anus, drawing water in for gas exchange (breathing via internal rectal gills) and expelling it forcefully for jet propulsion to escape danger or catch prey, a remarkable adaptation for their aquatic life. @googlefactss#insects#nowyouknow

Interesting Planet 🌍

@interesting_planet_facts · Post #421 · 26.07.2025 г., 00:22

🌎 Some cicada species spend 17 years underground as nymphs before emerging in huge synchronized swarms. This odd lifecycle helps them overwhelm predators and ensures their survival. ✨ #insects⚡#evolution⚡#adaptation 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1159 · 24.12.2025 г., 12:11

🌎 The orchid mantis of Southeast Asia blends in with flowers thanks to petal-shaped limbs and white, pink, or yellow coloring that matches local orchids. This insect both camouflages from predators and attracts pollinators, which it ambushes for food. ✨ #animals⚡#camouflage⚡#insects 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1246 · 22.01.2026 г., 18:11

🌎 The Indian leaf butterfly disguises itself as a dead leaf when at rest, with veins and brown patterns mimicking real foliage. When disturbed, it reveals bright blue and orange wings underneath—stunning colors that help startle predators. This butterfly is native to forests in South and Southeast Asia. ✨ #camouflage⚡#adaptation⚡#insects 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #378 · 21.07.2025 г., 18:22

🌎 The mimicry leaf insect looks exactly like a real leaf, down to brown spots that resemble decay. This remarkable disguise protects it from hungry predators by blending perfectly into the forest floor. ✨ #insects⚡#camouflage⚡#adaptation 👉subscribe Interesting Planet

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