Ранее я уже упоминал о другой фишке из ˍˍ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
🪐 The galaxy cluster Abell 1689, located about 2.2 billion light-years from Earth, has helped astronomers map out enormous amounts of dark matter—an invisible substance that makes up most of the cluster’s mass but can only be detected through its gravitational effects. By observing how Abell 1689 bends and magnifies the light from galaxies behind it (a phenomenon called gravitational lensing), scientists reveal a hidden universe shaped by something we still can't see. ✨
#darkmatter⚡#abell1689⚡#clustering⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
#typescript#cli#clustering#concurrency#dependency_injection#effect#error_handling#javascript#observability#opentelemetry#platform#schema#typescript#workflows
Effect is a powerful TypeScript framework that helps you build reliable and complex applications by managing side effects like logging, network calls, and database operations in a safe and organized way. It uses a core `Effect` type to describe workflows that are lazy, composable, and type-safe, allowing you to handle errors and dependencies explicitly. The framework is modular, with many packages for AI, CLI tools, distributed computing, SQL databases, and more, making it flexible for various needs. Using Effect improves code quality, concurrency handling, and maintainability, helping you write robust TypeScript apps efficiently[1][2][4][5].
https://github.com/Effect-TS/effect