About strings | Sololearn: Learn to code for FREE!


About strings

how multiplication works in between two strings.

11/20/2016 10:00:48 AM

Sree Latha

5 Answers

New Answer


The strings can't be multiplicated each other. But you can repeat a string with * (integer)


If the strings represent numbers, you can convert them to numbers, multiply the numbers and if needed, convert the result back to string


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...


For Sree Latha. In this case, "spam" and "eggs" are considered variables. print(spam*eggs)=4*5=20


spam=2 eggs=3 del spam spam=4 eggs=5 print(spam*eggs)