Ранее я уже упоминал о другой фишке из ˍˍ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
🌎 Wild African grey parrots are known to mimic not only human speech but also the calls of up to 30 other bird species in their habitat. This ability helps them integrate into mixed-species flocks and avoid predators by confusing potential threats. Parrots’ vocal learning is so advanced that some individuals can remember and use sounds for decades. ✨
#parrots⚡#intelligence⚡#communication
👉subscribe Interesting Planet
👉more Channels
🌎 African grey parrots rank among the best animal communicators. Scientific studies show they can understand hundreds of words, use them in context, and even grasp abstract concepts like “same” and “different.” One famous parrot, Alex, correctly identified shapes and colors and understood the concept of zero. ✨
#parrots⚡#cognition⚡#communication
👉subscribe Interesting Planet
👉more Channels
🌎 African grey parrots can solve multi-step logic puzzles and use words in meaningful context. In experiments, these parrots matched human toddlers in understanding basic concepts. The largest recorded vocabulary for one individual exceeded 1,000 words. ✨
#parrots⚡#animalbehavior⚡#cognition
👉subscribe Interesting Planet
👉more Channels
🌎 Parrots like the African grey can learn hundreds of words and use them to solve problems or request specific items. Studies show Alex, a famous African grey, identified colors, shapes, and quantities—demonstrating complex reasoning once thought exclusive to humans. ✨
#parrots⚡#cognition⚡#language
👉subscribe Interesting Planet