Ранее я уже упоминал о другой фишке из ˍˍfutureˍˍ , это оператор деления.
from __future__ import division
Суть проста. Раньше сложность типа данных результата поределялась типом самого сложного операнда.
Например:
int/int => int
int/float => float
В первом случае оба операнда int, значит и результат будет int. Во втором float более сложный тип, поэтому результат будет float.
Если нам требуется получить дробное значение при делении двух int то приходилось форсированно один из операндов конверировать в float.
12/float(5) => float
Но с новой "философией" это не требуется. В Python3 "floor division" заменили на "true division" а старый способ теперь работает через оператор "//".
>>> 3/2
1.5
>>> 3//2
1
То есть теперь деление int на int даёт float если результат не целое число.
В классах теперь доступны методы __floordiv__() и __truediv__() для определения поведения с этими операторами.
Данный переход описан в PEP238.
#pep#2to3#basic
🪐 The mysterious "dark flow" observed in the movement of galaxy clusters like Abell 3627 suggests that something unseen—possibly related to dark matter or dark energy—is pulling vast regions of the universe in the same direction. This large-scale motion, detected using X-rays from hot gas in clusters, remains unexplained by normal gravity and hints at the hidden forces shaping the cosmos beyond what we can directly observe. ✨
#darkmatter⚡#universe⚡#galaxyclusters⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Deep in the Coma Cluster, a packed group of over 1,000 galaxies, astronomers have measured how dark energy—a mysterious force causing the universe to expand faster over time—stretches the space between galaxies. Observations show that the distance between massive galaxies in the Coma Cluster grows not just from their own motion, but because dark energy is steadily pushing the entire cosmic structure apart. ✨
#darkenergy⚡#galaxyclusters⚡#cosmology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The Bullet Cluster, found in the constellation Carina, provides some of the clearest real-world evidence for dark matter—a mysterious, invisible substance making up most of the universe’s mass. When two galaxy clusters crashed together, X-ray images showed that most of the visible matter stayed at the center, but gravity maps revealed most of the mass had moved ahead, proving something unseen—dark matter—was driving the collision's aftermath. ✨
#darkmatter⚡#galaxyclusters⚡#carina⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The cosmic microwave background holds a hidden fingerprint—tiny temperature fluctuations mapped in exquisite detail by satellites like Planck reveal how the first stars and galaxies, such as those in the ancient cluster Abell 2744, grew from initial small ripples in the early universe. These faint variations, just millionths of a degree, became the seeds around which all the cosmic structures we see today first assembled. ✨
#cosmicmicrowavebackground⚡#earlyuniverse⚡#galaxyclusters⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The cosmic microwave background contains faint "Sunyaev-Zel’dovich effects," which happen when the ancient microwave light passes through hot gas in galaxy clusters like the Bullet Cluster. This process boosts the energy of some photons (light particles), leaving tiny shadows in the background glow—allowing astronomers to map both distant galaxy clusters and the hot plasma between galaxies by studying these subtle marks in the oldest light in the universe. ✨
#microwave⚡#background⚡#galaxyclusters⚡#plasma⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels