Ранее я уже упоминал о другой фишке из ˍˍ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
⚡️ Game Adjustment Alert ⚡️
Starting from floor 2, rooms without NFT will see a 50% decrease in earnings! 👀
Application time: From 13:00 UTC - Oct 9
You know what to do! Don’t let those NFTs sit idle in the Vault—equip them NOW for max earnings 💥🎤
#SingSingTycoon#NFTPower
🎤Announcement | Chat | X (Twitter) | Website | Game
🎤 Ready to take your karaoke empire to the next level? With Karaoke Box NFT and KTV NFT, the path to becoming the ultimate tycoon is within reach!
💥 Karaoke Box NFT is your ticket to faster earnings! The rarer the box, the more your earning speed skyrockets:
Common ➡️ x1.5 earning speed
Uncommon ➡️ x2 earning speed
Rare ➡️ x4 earning speed
Epic ➡️ x6 earning speed
Legendary ➡️ x8 earning speed
🏢 Meanwhile, the KTV NFT is key to unlocking more floors, allowing your karaoke chain to expand beyond limits:
Common ➡️ +1 floor
Uncommon ➡️ +3 floors
Rare ➡️ +5 floors
Epic ➡️ +10 floors
Legendary ➡️ +15 floors
✨ The rarer the NFT, the bigger the rewards! Time to upgrade and watch your karaoke business thrive like never before! 🚀
Check out how to leverage your NFTs here: https://t.me/singsingchannel/831
#SingSingTycoon#NFTPower
🎤Announcement | Chat | X (Twitter) | Website | Game