Ранее я уже упоминал о другой фишке из ˍˍ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
🌎 Some Himalayan glaciers are “surge glaciers,” moving up to 100 times faster than normal for short periods. These icy rivers can suddenly speed up, advancing kilometers in months instead of centuries—reshaping valleys with astonishing power. ✨
#glacier⚡#Himalayas⚡#earth
👉subscribe Interesting Planet
🌎 Greenland’s Ilulissat Icefjord is packed with icebergs from one of the world’s fastest glaciers. Its towering ice flows calve off at such speed that they helped inspire the iceberg that sank the Titanic! ✨
#glacier⚡#iceberg⚡#Greenland
👉subscribe Interesting Planet
Glacier covered in massive blanket to stop melting
A cloth sheet used to shield part of the Helags glacier in northern Sweden over the summer saved at least 3.5 meters in height from melting, according to organizers of the private initiative, the first of its kind in Scandinavia.
#News#Reuters#environment#globalwarming#Sweden#glacier
Subscribe: http://smarturl.it/reuterssubscribe
Reuters brings you the latest business, finance and breaking news video from around the globe. Our reputation for accuracy and impartiality is unparalleled.
Get the latest news on: http://reuters.com/
Follow Reuters on Facebook: https://www.facebook.com/Reuters
Follow Reuters on Twitter: https://twitter.com/Reuters
Follow Reuters on Instagram: https://www.instagram.com/reuters/?hl=en
➖@reutersworldchannel➖