Python multiplication is done with *
, the multiplication operator:
>>> 8 * 3
24
>>> 3 * 2 * 1
6
Multiplying floats:
>>> 8.3 * 2.6
21.580000000000002
Note that floating point operations can produce small rounding errors, 8.3 * 2.6 is not necessarily 21.58.
If any of the numbers in the operation are floats, Python will return a float.
Multiplying negatives:
>>> -8 * -11
88
The multiplication operator can also be used to multiply certain data types, like strings, lists, and tuples:
>>> [3, 2] * 2
[3, 2, 3, 2]
>>> "hello" * 2
'hellohello'
>>> (3, 2) * 2
(3, 2, 3, 2)