Ранее я уже упоминал о другой фишке из ˍˍ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
🪐 Scientists using the Green Bank Telescope detected a persistent radio signal from Proxima Centauri, the closest star to our Sun, sparking interest due to its unusual nature. Although later studies found the signal was most likely caused by human technology, Proxima Centauri remains a key target in the search for alien life because it hosts the potentially habitable planet Proxima b. ✨
#aliens⚡#exoplanets⚡#proximacentauri⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The SETI Institute's ongoing Breakthrough Listen project regularly targets the region around the star Proxima Centauri—our solar system’s closest neighbor—searching for unusual radio signals that could hint at alien technology. By scanning billions of radio frequencies from Proxima Centauri and other nearby stars, scientists are using real astronomy to explore whether advanced extraterrestrial civilizations might exist within our interstellar neighborhood. ✨
#aliens⚡#ProximaCentauri⚡#SETI⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The future of interstellar travel may hinge on new propulsion ideas being studied today, like nuclear electric propulsion—which uses nuclear reactors to generate electricity for ultra-efficient ion engines. NASA has tested this kind of technology in missions like Deep Space 1, and scientists hope that one day, such systems could send spacecraft toward distant stars like Proxima Centauri far faster than chemical rockets ever could. ✨
#spaceships⚡#propulsion⚡#ProximaCentauri⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Scientists are investigating laser-driven spacecraft, where powerful laser beams from Earth could propel tiny probes at speeds up to 20% that of light—fast enough to reach Proxima Centauri, our closest neighboring star system, in just over 20 years. This approach, known as "light sail" propulsion, uses intense light pressure against a thin, reflective sail to accelerate a probe, offering a glimpse of how interstellar journeys could become possible within a human lifetime. ✨
#spaceships⚡#ProximaCentauri⚡#lightsail⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The challenge of reaching other star systems like Proxima Centauri, over 4 light-years away, drives scientists to explore futuristic spaceship concepts beyond anything in use today. One promising idea is fusion propulsion, which would harness the power of fusing atomic nuclei—just like in the Sun—to generate immense thrust, potentially making journeys to nearby stars possible in a matter of decades rather than millennia. ✨
#fusion⚡#propulsion⚡#spaceships⚡#ProximaCentauri⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels