Ранее я уже упоминал о другой фишке из ˍˍ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
#quoteoftheday
💬“If you are not embarrassed by the first version of your product, you launched too late.” — Reid Hoffman, LinkedIn co-founder
🚀 While you are redesigning your logo for the tenth time, someone else is already monetizing their product at the MVP stage.
Follow Startup Base to stay updated on startups, opportunities, and the latest trends.
@startupbaseuz
LinkedIn | Facebook | Instagram | Website
#quoteoftheday
💬“Agar mahsulotingizning birinchi versiyasidan uyalmasangiz, siz uni juda kech ishga tushiribsiz”—Rid Hofman, LinkedIn asoschilaridan biri
🚀Siz logotipni o‘ninchi bor o‘zgartirayotganingizda, kimdir allaqachon mahsulotini MVP’da pullayapti.
Startaplar, ularga oid imkoniyatlar va trendlardan xabardor bo‘lish uchun Startup Base’ni kuzatib boring.
@startupbaseuz
LinkedIn | Facebook | Instagram | Website
☀️#Quoteoftheday
😇“Don't let yesterday take up too much of today.”
- Will Rogers
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring
☀️#Quoteoftheday
😇“You cannot protect yourself from sadness without protecting yourself from happiness.”
- Jonathan Safran Foer
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring
☀️#Quoteoftheday
😇“It's up to you how far you go. If you don't try, you'll never know!”
- Merlin, "Sword in the Stone"
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring
☀️#Quoteoftheday
😇“Pursue the things you love doing and then do them so well that people can’t take their eyes off of you.”
- Maya Angelou
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring
☀️#Quoteoftheday
😇“This is your life. Do what you love, and do it often.”
- Holstee Manifesto
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring
☀️#Quoteoftheday
😇“Focus is the art of knowing what to ignore.”
- James Clear
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring
☀️#Quoteoftheday
😇“Always remember that the future comes one day at a time.”
- Dean Acheson
❤️@QuotesPoint
✅@Quotes_Positive_Inspirational
✔️@Quotes_Motivational_Inspiring