Ранее я уже упоминал о другой фишке из ˍˍ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
🔋🇺🇸EV REVOLUTION IN REVERSE — NEW ELECTRIC CAR SALES CRASH 27% AS TAX CREDITS VANISH
🔹 Q1 sales plummet to just 216k units as post-credit shock decimates demand — market share nosedives from 10.5% to 4.8% 📉
🔹 Ford EV deliveries obliterated by 70% while Honda collapses 81% — automakers bleeding red ink on every unit sold 🏭
🔹 Used electric cars hit record 43k monthly sales as buyers refuse to pay full sticker on brand new models 🚗
🔹 Nissan cancels US factory plans entirely while battery makers scramble for shrinking order books worldwide 🔧
Americans love the idea of EVs — they just refuse to pay premium prices without Uncle Sam's help 💀🔥
#EVCrisis#AutoNews
@america
🚗✨Lexus Unveils Upgraded LC Coupe and Convertible!✨🚗
Since its debut in 2017, the Lexus LC family has received a sleek exterior makeover and new interior materials. But that's not all! The updated models now feature a stiffer chassis, thanks to additional braces installed under the floor near the front and rear axles, enhancing overall handling. 🏎️💨
Under the hood, the Lexus LC offers a powerful lineup: a 5.0L V8 engine producing 477 hp or a hybrid V6 powertrain with a 3.5L engine delivering 359 hp. 🔥🔋
#LexusLC#LuxuryCars#CarEnthusiast#DrivingExperience#AutoNews#V8Power#Auto
🚙✨ Exciting News! The new Mitsubishi Pajero Sport has hit the testing grounds! 🛤️🔍
Despite its camouflage, it's clear that the front design draws inspiration from the current L200/Triton pickup. 🛻💨 The new front end beautifully complements the familiar rear styling.
Could this be a prototype testing individual components in a non-production body? 🤔🔧
While the release date remains a mystery, the current model is set to be discontinued in 2025. ⏳📅
#MitsubishiPajeroSport#CarTesting#NewRelease#Mitsubishi#SUV#AutoNews#Innovation#Auto