add, mul operators also support strings

Jan. 23, 2022
3:57 p.m.
https://docs.python.org/3/library/operator.html says "operator.add ... Return a + b, for *a* and *b* numbers " and "operator.mul... Return a * b, for *a* and *b* numbers" but both of those also work on strings [0] (and perhaps other types):
import operator operator.add('s', 't') 'st' operator.mul('a', 3) 'aaa' operator.mul(3, 'b') 'bbb'
[0] "Strings can be concatenated (glued together) with the + operator, and repeated with *"
3 * 'un' + 'ium''unununium'
https://docs.python.org/3/tutorial/introduction.html#strings
1158
Age (days ago)
1158
Last active (days ago)
0 comments
1 participants
participants (1)
-
Gabriel Sroka