Ранее я уже упоминал о другой фишке из ˍˍ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 disappearance of the Sodder children in 1945 remains unsolved. Five siblings vanished after a house fire in Fayetteville, West Virginia. Investigators found no remains in the ash, and sightings were later reported but never verified. A billboard seeking answers stood along Route 16 for decades. ✨
#history⚡#disappearance⚡#mystery
👉subscribe Interesting Planet
🌎 In 2009, French aircraft Air France Flight 447 disappeared over the Atlantic during a flight from Rio de Janeiro to Paris. All 228 people on board died. The plane's wreckage was not found for nearly two years, when deep-sea searches located the main debris field at a depth of 3,900 meters. ✨
#aviation⚡#disappearance⚡#ocean
👉subscribe Interesting Planet
👉more Channels
🌎 In 1815, the British brig HMS Rosalie was found abandoned and drifting near the Bahamas. The ship’s sails were set, and cargo untouched, but not a single crew member was found onboard. Official records note that the ship’s logbook and personal belongings were still present when discovered. ✨
#disappearance⚡#maritime⚡#mystery
👉subscribe Interesting Planet
🌎 In 1973, Australian pilot Frederick Valentich disappeared while flying a Cessna 182L over Bass Strait. During radio contact, he reported a strange, unidentified craft circling his plane before transmission was lost. Despite a large search, neither Valentich nor his aircraft were ever found. ✨
#disappearance⚡#aviation⚡#australia
👉subscribe Interesting Planet
👉more Channels
🌎 In 1872, the Mary Celeste was found adrift in the Atlantic Ocean—its crew vanished without a trace, leaving food, cargo, and the ship untouched. This unsolved maritime mystery has puzzled historians ever since. ✨
#disappearance⚡#ship⚡#mystery
👉subscribe Interesting Planet
🌎 In 1925, British explorer Percy Fawcett vanished in Brazil's Amazon rainforest while searching for the lost city of "Z." Fawcett, his son, and a companion were last seen near the Upper Xingu River. Despite dozens of rescue missions over decades, no confirmed trace of the expedition was ever found. ✨
#amazon⚡#disappearance⚡#exploration
👉subscribe Interesting Planet
👉more Channels