@googlefactss · Post #40777 · 12.03.2026 г., 07:01
A group of jellyfish is called a bloom, swarm, or smack. @googlefactss#nowyouknow
Hashtags
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
Пребарај: #nowyouknow
@googlefactss · Post #40777 · 12.03.2026 г., 07:01
A group of jellyfish is called a bloom, swarm, or smack. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40758 · 07.03.2026 г., 15:04
Jellyfish move in essentially two ways. They take water in their bell and then squirt it out behind them, which creates a jet of water that moves them forward. They also drift on water currents. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40710 · 27.02.2026 г., 07:04
Horseshoe crabs are not crabs at all. They are not even crustaceans. Instead, they have their own separate class named Merostomata. They have hardly changed since the age of the dinosaurs, and their closest-living relatives are spiders @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40525 · 11.01.2026 г., 19:02
Blind people smile even though they have never seen anybody else smile. Facial expressions like smiling are largely innate and biological, not just learned through visual imitation and not learned at all. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39979 · 30.10.2025 г., 08:02
Stan is an ancient Persian word meaning “land” or “nation,” and Kazakh means “wanderer,” “adventurer,” or “outlaw.” Therefore, the name Kazakhstan translates as “Land of the Wanderers. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39972 · 29.10.2025 г., 08:48
In terms of absolute size and in proportion to overall body mass, the human penis is longer and thicker than that of any other primate. For instance the average size of the human penis is 8-10 cm when flaccid and 13-15 cm when erect while gorillas, which are the largest primates, have a penis size of approximately 4 cm in length when erect. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39942 · 23.10.2025 г., 07:58
The colors of fire hydrants give a reasonably accurate picture as to how much water flow and pressure they can provide @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39922 · 13.10.2025 г., 12:57
The position dogs assume when they are inviting other pets to play is called a play bow. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39899 · 03.10.2025 г., 22:04
The historical figure who inspired the Santa Claus legend, Saint Nicholas, was born in Patara, Turkey, in the 3rd century A.D. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39888 · 29.09.2025 г., 17:20
Greek philosopher Aristotle (384–322 BC) thought the heart, not the brain, was the center of mental functions, emotions, and intellect. He considered the heart the core of the body's "psychical fire" and the source of its heat, with the brain's main role being to cool the blood. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39885 · 29.09.2025 г., 13:02
The al-Qarawiyyin Library in Fez, Morocco is the oldest working library in the world. It was founded in 859 CE by Fatima al-Fihriya. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40641 · 09.02.2026 г., 15:02
Napoleon I banned fashion dolls because he was nervous they could be used to send secret messages. [Read more] @googlefactss#nowyouknow#history
Hashtags