0

About strings

how multiplication works in between two strings.

20th Nov 2016, 10:00 AM
Sree Latha
Sree Latha - avatar
5 Réponses
+ 8
The strings can't be multiplicated each other. But you can repeat a string with * (integer)
20th Nov 2016, 10:05 AM
Leo
Leo - avatar
+ 3
If the strings represent numbers, you can convert them to numbers, multiply the numbers and if needed, convert the result back to string
20th Nov 2016, 11:34 AM
attexx
attexx - avatar
0
Alain, you're wrong. Your example doesn't work, because you multiply None that print returns by 10 and it gives an error : >>> print ("@") * 10 @ Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> print ("@") * 10 TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' Here is the correct example: print('coding...'*5) coding...coding...coding...coding...coding...
20th Nov 2016, 1:49 PM
donkeyhot
donkeyhot - avatar
0
For Sree Latha. In this case, "spam" and "eggs" are considered variables. print(spam*eggs)=4*5=20
20th Nov 2016, 1:59 PM
Leo
Leo - avatar
- 2
spam=2 eggs=3 del spam spam=4 eggs=5 print(spam*eggs)
20th Nov 2016, 1:46 PM
Sree Latha
Sree Latha - avatar