Ранее я уже упоминал о другой фишке из ˍˍ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
🌍 Libya’s Libyan Desert holds sand seas with dunes reaching up to 180 meters tall. These giant dunes constantly shift with the wind, creating landscapes that can look completely different in just a few years. ✨
#desert⚡#dunes⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In the Taklamakan Desert of China, some sand dunes reach up to 300 meters tall. Shifting winds keep these giant dunes moving, constantly reshaping the landscape year after year. ✨
#deserts⚡#dunes⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 In Australia’s Simpson Desert, certain red sand dunes can “move” up to a meter each year as winds slowly push millions of grains, gradually shifting entire hills across the arid landscape. ✨
#deserts⚡#dunes⚡#Australia⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The world's highest coastal dune towers 352 meters above sea level at Pilat Dune in France. This massive sand formation shifts yearly as Atlantic winds pile new layers along the shore. ✨
#seacoast⚡#dunes⚡#landscape⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The Namib Sand Sea is the only coastal desert made entirely of shifting sand dunes recognized as a UNESCO World Heritage site, with winds constantly sculpting waves of sand along the Atlantic coast. ✨
#desert⚡#dunes⚡#Namibia⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels