Ранее я уже упоминал о другой фишке из ˍˍ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
🌍 In Chile's Atacama Desert, rare fog called "camanchaca" drifts inland from the Pacific. Some plants here survive by absorbing water directly from this fog, not from rainfall. ✨
#desert⚡#arid⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Some arid desert landscapes feature ancient, dried-up riverbeds called wadis that can flood suddenly after rare rains, quickly turning from bare channels to rushing streams in a matter of hours. ✨
#desert⚡#arid⚡#landscapes⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 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🌍
🌍 The Atacama Desert in Chile is so dry that some weather stations have never recorded rain. Its Mars-like soils are studied by scientists searching for signs of life in extreme environments. ✨
#desert⚡#extreme⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The Namib Desert is thought to be the oldest desert on Earth, with arid conditions lasting for at least 55 million years—far longer than any other known desert. ✨
#desert⚡#Namib⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍