Ранее я уже упоминал о другой фишке из ˍˍ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
🌍 Earth’s axis tilts about 23.5 degrees, causing our changing seasons. Without this tilt, much of the planet would have no summer or winter—just constant day or night at the poles. ✨
#earth⚡#seasons⚡#planet⚡#geography⚡#nature
👉subscribe Amazing Geography
👉more Channels
🪐 Uranus spins on its side compared to most planets, with its axis tilted at about 98 degrees from vertical. This extreme tilt means that each pole spends over 40 years in continuous sunlight, followed by 40 years of darkness, creating some of the most unusual seasonal changes among the giant planets. ✨
#Uranus⚡#seasons⚡#giants⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
Angola has two seasons: summer and cacimbo. Summer is warm and rainy from October to April. Cacimbo is dry and cooler from May to September.
@googlefactss
🌞🌧️❄️#Angola#Seasons#Weather#Climate
💋 Peach loves to be with Goma in every season of the year. 🍂🍃🌨️
What's your favorite season?
😍
#Nature#Seasons#Summer#Winter#Autumn#Monsoon#Cats#Cute#lovers#story#couples#catsoftelegram
💃@PeachLovesGoma
💃