Ранее я уже упоминал о другой фишке из ˍˍ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
🚀 Excited to announce that our partner, Cowtopia, has officially launched their new game!
🎉 Tons of opportunities for users to experience and earn profits await. Join now and explore the world of Cowtopia! 🌟
#Cowtopia#Gaming#Profit#JoinNow#SingSing Partnership
Follow Cowtopia🐮
Channel | Chat | Twitter | Website
🚨 Last Chance: SLEX Whitelist is Coming to an End! ⏳
🔥Time is ticking! The exclusive opportunity to join the SLEX Whitelist only for the community is nearing its end on February 1st. This is an exceptional way to get early access to a limited allocation of SLEX Coins before Public listing!
🤝Take your last chance and join SLEX Whitelist: slex.io/launchpad/slex
🤔We've also got an exciting way to show you the ambitious and in-depth look at SLEX plans and vision on Binance:www.binance.com/en-AE/feed/post/1058789
#SLEXWhitelist#SLEXExchange#JoinNow#BinanceArticle#SLEXCoin#PublicSale#SLEXLaunchpad
Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter
🚀🔥 Crypto Melt Pot – The Next Big Gem is Here! 🔥
Let’s build something massive together! 🌍
We’re creating a strong community where everyone grows and earns together. 💰
👉 Join our movement now – don’t stay behind!
💎 Be part of the early believers, support the project, and buy the token before the pump! 🚀
📢 Official Links:
🔗 Telegram: Join the Community
🐦 Twitter (X): Follow Us
💰 Contract Address (CA):
GRxRRM4fkfFUmniJspwn8beiXdfffXrBDpbooaKkpump
🔥 Let’s grow, trade, and win together — the earlier you join, the more you earn! 💸
#CryptoMeltPot#Solana#DeFi#PumpToken#CryptoGem#JoinNow#BuyTheDip#CryptoCommunity