Ранее я уже упоминал о другой фишке из ˍˍ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 which language does "39" (spoken as san kyuu) sound like "thank you" due to the influence of English?
🧠 Follow @languagetrivia for more
#numbers
Check out the correct answer in the comments
In which language is "520" commonly used in messaging to mean "I love you"?
🧠 Follow @languagetrivia for more
#regular_multiple_choice#numbers
Check out the correct answer in the comments
How many English words made their first recorded appearance in Shakespeare’s writings?
A) 200
B) 1700
C) 4000
D) 18000
Take the quiz below to check if you guessed it right
@languagetrivia#numbers#history
The Week in Numbers: Christmas is cancelled
Chinese coal prices are at record levels, U.S. gasoline is at seven-year highs and benchmark crude climbs by the day. Signs of an energy crunch can be found wherever you look. More of the big numbers in business from the past week.
#News#Reuters#numbers#energycrisis#France#Bitcoin
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➖