Ранее я уже упоминал о другой фишке из ˍˍ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
#LifeatIRAS goes beyond just ticking off tasks; it's a vibrant journey filled with continuous learning and collaborative opportunities! 🌟
Techies, this one's for you! 👨💻 Tune in to the full video where Steven and Chanel spill the tea on the pivotal role of techies in the tax industry: https://youtu.be/OWWZ1Z6xUlc
#WhyIDoWhatIDo#IRASGameOn#irassg#taxtech#techroles#careerideas
The weather has been so hot 🥵🔥 Who else wants to work in a cold room too? 🙋
Learn more about what Shaun and Sakthi do and why they choose #lifeatIRAS: https://www.youtube.com/watch?v=KGDBnQv31WA
Find your role with us at go.gov.sg/lifeatiras💡⭐️
#WhyIDoWhatIDo#IRASGameOn#irassg#taxtech#beattheheat#careerideas
Quote Georgina, “Our work is NOT boring!” 😂
Watch the full video as Sanudha and Georgina dish more about their #lifeatIRAS experiences!
Find your role with us at go.gov.sg/lifeatiras💡⭐️
#WhyIDoWhatIDo#IRASGameOn#irassg#interestingjobs#taxtech#careerideas
Ever wonder what's behind the scenes of tax investigation? 🕵️♂️ Our investigator, Jeremy, reveals his most intriguing tool – a door ram! 🚪
Watch the full video as Jeremy and Juliana explain the difference between a tax investigator and a tax auditor.
Find your role with us at go.gov.sg/lifeatiras💡⭐️
#WhyIDoWhatIDo#IRASGameOn#irassg#taxtech#investigation#audit#careerideas#lifeatIRAS