Ранее я уже упоминал о другой фишке из ˍˍ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
R✨e✨m✨e✨m✨b✨e✨r
Never forget
- Good luck, Have Fun, Don't Die.. 2026 Film putting it right in our faces. Real eyes Realize Real Lies. ..
,•°°•ꨄ•°°•,
✨🌞✨
’•✧•’
( Big Homie )¯\_(ツ)_/¯
All the world is their stage. 🎬
𝐄 𝐍 𝐉 𝐎 𝐘 | 🌟🌟🌿
#Wisdom
It's not what we bought but what we built
It's not what we got but what we shared
It's not our competence but our characters
And it's not our success but our significance
Live a life that matters. Live a life of love.
Unknown
#wisdom
@quietworld🍃
The day the child realizes that all adults are imperfect he becomes an adolescent; the day he forgives them, he becomes an adult; the day he forgives himself he becomes wise.
– Alden N –
#wisdom
@quietworld🍃
We judge people by what they see and hear, but we do not see the qualities that are hidden in their hearts. Avoid suspicion. Let's not say bad things about each other. Let us not gossip or insult.
#wisdom
We can control the words we say, but we can't control what people understand.
We can control what we say to people, but we can't control what other people say to others about us.
That's normal and just a part of life so be it. I'm at peace when I control only what I can control and refuse to take part in things that I cannot control especially those which do not matter at all. ☺️✨🦋
#thoughts#wisdom
@quietworld🍃
To live only for some future goal is shallow. It’s the sides of the mountain that sustain life, not the top.
– Robert M. Prisig
#life#wisdom
@quietworld🍃