Ранее я уже упоминал о другой фишке из ˍˍ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
🇧🇩#Bangladesh – Il National Citizen Party (#NCP), fondato dagli studenti Gen Z che hanno portato alla caduta dell’ex premier Sheikh #Hasina, si coalizzerà con i partiti islamisti in vista delle elezioni di febbraio. Diversi dirigenti e candidati riformisti si sono dimessi in seguito alla decisione che potrebbe portare il clero islamico al governo.
@UltimoraPolitics24
News: Former #Sudan PM Hamdok says Islamist factions major obstacle to ending war
Abdalla Hamdok, Former Sudanese Prime Minister and head of the Somoud civilian coalition, has said Islamist factions linked to Sudan’s former ruling party are among the main obstacles to ending the country’s nearly three-year civil war, according to a report by Abu Dhabi-based newspaper The National.
Speaking to the newspaper on the sidelines of the 39th African Union summit in #Addis_Abeba, Hamdok said Islamist groups and the National Congress Party (#NCP) — the political party of ousted president Omar Al Bashir — remains key actors resisting peace initiatives and efforts to reach a broader national consensus.
He also criticized Sudan’s army chief, Gen Abdel Fattah #Al_Burhan, for insisting on a military solution to defeat the rival Rapid Support Forces (#RSF). Al Burhan has publicly ruled out peace....
https://web.facebook.com/AddisstandardEng/posts/pfbid02qycixQfoRJLo5F9EWtxgsymfNbxMqUa9D4Qquz6X3DjfUBUFxig1b3xTGb3MzEHHl
🇧🇩#Bangladesh – Oggi oltre 120 milioni di cittadini sono stati chiamati alle urne per rinnovare i 350 seggi del Parlamento, le prime elezioni dopo la deposizione della premier Sheikh #Hasina e la messa al bando della Lega Awami. Si sono sfidati il Partito Nazionalista Bengalese (#BNP) di Tarique #Rahman (rientrato dall’esilio a Londra dopo 17 anni), di centro-destra, per la liberalizzazione dell’economia, vicino alla classe media e all’esercito, e la coalizione guidata dal partito islamista Jamaat-e-Islami (#Jamaat) di Shafiqur #Rahman, che punta a introdurre la sharia nel Paese. La coalizione include il Partito Nazionale dei Cittadini (#NCP), fondato dai leader delle proteste studentesche, ma l’alleanza con gli islamisti è stata fortemente contestata da donne, laici e minoranza indù che avevano sostenuto le proteste. Risultati nelle prossime ore.
@UltimoraPolitics24