Ранее я уже упоминал о другой фишке из ˍˍ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
🤖A unique art exhibition Neuro Conflict will take place in Bali
📍 This weekend from 12 to 14 July, Superlative Gallery in Kuta will host an unusual exhibition called Neuro Conflict. Here you can experience a unique combination of art and modern technology, including neural networks.
🤖 The event will run for three days. The exhibition will feature works by international artists, interactive art installations, fascinating lectures on artificial intelligence, as well as performances and an auction.
@BaliNews
#wheretogo#exhibitions#Kuta
🧉Bali will host the official Arak Day tomorrow
🏝 Arak Day, the local palm vodka, is celebrated tomorrow, January 29.
ℹ️ Arak is a symbol of offering to the gods for a rich harvest, a form of gratitude.
📍 The official event will be held at GWK Park. The “Arak Berem Bali for the World” exhibition will also be held there.
🐲 The organizers of the celebration emphasize that Arak Day in Bali is not about drinking at all. Arak Day celebrations should be understood as a temple festival that is celebrated through prayer, not alcoholism.
@BaliNews
#holidays#events#exhibitions#culture