Multiplication

Download python eBook

Example

a, b = 2, 3

a * b                  # = 6

import operator
operator.mul(a, b)     # = 6

Possible combinations (builtin types):

  • int and int (gives an int)
  • int and float (gives a float)
  • int and complex (gives a complex)
  • float and float (gives a float)
  • float and complex (gives a complex)
  • complex and complex (gives a complex)

Note: The * operator is also used for repeated concatenation of strings, lists, and tuples:

3 * 'ab'  # = 'ababab'
3 * ('a', 'b')  # = ('a', 'b', 'a', 'b', 'a', 'b')

Stats

Contributors: 7
2016-12-29
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook