Ранее я уже упоминал о другой фишке из ˍˍ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
Мир продолжает понемногу отходить от массового зеленого умопомрачения. General Motors готовится представить новые двигатели V8, в разработку вложили почти $1 млрд.
Появится сразу два агрегата, 5,7 и 6,6 литра. Первый для таких моделей, как Chevrolet Silverado 1500. Второй – для ряда Corvette. Обещают, что они будут не простыми большими, а большими и технологичными.
По крайней мере в США выбор не будет ограничен перекрученными 2-х литровыми моторами.
#v8
🚗✨Maserati Unveils the Final Quattroporte with V8 – Grand Finale!🎉
This stunning vehicle, custom-made for a client in the USA, showcases a unique and exquisite design. 🌟🇺🇸 With the V8 engine now retired from the lineup, including the Ghibli sedan and Levante SUV, this masterpiece marks the end of an era.
A true symbol of luxury and performance! 🏁💎
#Maserati#Quattroporte#V8#GrandFinale#LuxuryCars#Auto🚘💖
🚗💨 Exciting news from Lamborghini! The upcoming Lamborghini Temerario is set to unleash over 1000 horsepower! 🔥
Ruwen Mor, a former Audi engineer now at Lamborghini, revealed that the power of the V8 engine could increase from 200 to around 220 hp per liter. Plus, the car will feature three electric motors for an extra boost! ⚡️
The Temerario follows in the footsteps of the iconic Huracan, which had a naturally aspirated V10 engine with a peak output of 640 hp. While a V6 could have delivered even more power, the decision was made to stick with a higher cylinder count to meet customer expectations. 💪
#Lamborghini#Temerario#Supercar#1000HP#V8#ElectricPower#CarEnthusiast#LuxuryCars#Auto