@sgmrt · Post #1757 · 04.07.2023 г., 23:24
[EWL] UPDATE: Train svc btwn #TuasLink and #TuasWestRoad has resumed. Free regular bus and bridging bus services have ceased. - SMRT
Hashtags
TGINSIGHT SIMILAR POSTS
Изворен канал @pythonotes · Post #156 · 2 окт.
Те, кто в Python не первый день, хорошо знают, что на число можно умножить не только число, но и другие типы. Главное, чтобы у этих типов была реализация такой операции. # list >>> [1] * 3 [1, 1, 1] # tuple >>> (2, 3) * 3 (2, 3, 2, 3, 2, 3) # string >>> "A" * 3 "AAA" Так работает полиморфизм стандартных типов. Интересно здесь то, что это сработает и в том случае, когда порядок операндов обратный. То есть int умножить на [тип]. # list >>> 3 * [1] [1, 1, 1] # tuple >>> 3 * (2, 3) (2, 3, 2, 3, 2, 3) # string >>> 3 * "A" "AAA" Если хотите реализовать такое поведение в ваших классах то следует помнить два момента: 1. Если множитель справа, то вам нужно реализовать метод __mul__, наш класс это первый операнд, то есть слева. myType * 3 2. Если множитель слева, то вам нужно реализовать метод __rmul__, наш класс это второй операнд, справа. 3* myType Всё тоже самое можно делать и для других математических операторов. И если в этом примере действие и результат будут фактически одинаковыми, то бывают ситуации, когда это не так. Например, при умножении матриц имеет значение порядок операндов. Для других операторов, таких как деление или сдвиг, очень важно кто с какой стороны находится. >>> 2/4, 4/2 (0.5, 2.0) >>> 2<<3, 3<<2 (16, 12) >>> 100%15, 15%100 (10, 15) #tricks#basic
Пребарај: #tuaslink
@sgmrt · Post #1757 · 04.07.2023 г., 23:24
[EWL] UPDATE: Train svc btwn #TuasLink and #TuasWestRoad has resumed. Free regular bus and bridging bus services have ceased. - SMRT
Hashtags
@sgmrt · Post #1756 · 04.07.2023 г., 23:13
[EWL]: Due to a factory fire near #TuasLink, there is no train svc btwn #TuasLink and #TuasWestRoad. Free regular bus and bridging bus services are available btwn #TuasLink and #TuasWestRoad. Train service is still available. - SMRT
Hashtags
@sgmrt · Post #1755 · 04.07.2023 г., 22:53
[EWL]: Due to a factory fire near #TuasLink, there is no train svc btwn #TuasLink and #TuasWestRoad. Free regular bus and bridging bus services are available btwn #TuasLink and #TuasWestRoad. Train service is still available. - SMRT
Hashtags
@sgmrt · Post #1754 · 04.07.2023 г., 22:38
[EWL]: Due to a factory fire near #TuasLink, there is no train svc btwn #TuasLink and #TuasWestRoad. Free regular bus and bridging bus services are available btwn #TuasLink and #TuasWestRoad. - SMRT
Hashtags
@sgmrt · Post #1753 · 04.07.2023 г., 22:14
[EWL]: Due to a factory fire near #TuasLink, there is no train svc btwn #TuasLink and #TuasWestRoad. Free regular bus and bridging bus services are available btwn #TuasLink and #TuasWestRoad. - SMRT
Hashtags
@sgmrt · Post #1752 · 04.07.2023 г., 21:58
[EWL]: Due to a factory fire near #TuasLink, there is no train svc btwn #TuasLink and #TuasWestRoad. Free regular bus services are available btwn #TuasLink and #TuasWestRoad. - SMRT
Hashtags
@sgmrt · Post #1751 · 04.07.2023 г., 21:33
[EWL]: Due to a factory fire near #TuasLink, there is no train svc btwn #TuasLink and #TuasWestRoad. Free regular bus services are available btwn #TuasLink and #TuasWestRoad. - SMRT
Hashtags
@sgmrt · Post #1397 · 24.12.2021 г., 22:39
[EWL] UPDATE: Free regular bus & free bridging bus svcs btwn #TuasLink and #JooKoon have ended. - SMRT
@sgmrt · Post #1395 · 24.12.2021 г., 22:11
[EWL] UPDATE: Free regular bus & free bridging bus svcs btwn #JooKoon and #TuasLink. - SMRT
@sgmrt · Post #1399 · 24.12.2021 г., 22:56
[EWL] CLEARED: Train svcs btwn #TuasLink and #TuasCrescent have resumed. - SMRT
Hashtags
@sgmrt · Post #1398 · 24.12.2021 г., 22:40
[EWL] UPDATE: Train svc is available btwn #TuasLink and #TuasCrescent. - SMRT
Hashtags
@sgmrt · Post #1396 · 24.12.2021 г., 22:11
[EWL]: Due to a signalling fault, pls add 15mins train travel time btwn #TuasLink and #TuasCrescent. - SMRT
Hashtags