+ 2

When i wrote print("x"*x) where x=7 i got output xxxxxx .

why

6th Feb 2019, 5:10 PM
Daivik Pandya
Daivik Pandya - avatar
3 Respostas
+ 4
Multiplying a string by a number is usually nonsense in programming languages but python enables it and the result is the string concatenated x times. The string itself in the above example, "x" does not refer to the variable or the value 7, it could just as well be "ham" and then the result would be hamhamham.... 7 times.
6th Feb 2019, 5:38 PM
Tibor Santa
Tibor Santa - avatar