+ 1

How did he come up with this answer

>>> 4 * '2' '2222'

21st Sep 2017, 4:49 PM
MelioCurry
MelioCurry - avatar
3 ответов
+ 5
When an object is enclosed in double or single quotes then it is considered as a string. Here 2 is considered as a string and when a string multiplied with 4 it is repeated 4 times and thus output is '2222'
21st Sep 2017, 4:58 PM
Lakshay
Lakshay - avatar
+ 3
'2' is a string, like 'a' or 'spam' once you multiply it for a number, you are actually repeating it n times so, 'spam'*4 prints out 'spamspamspam' give a try
21st Sep 2017, 4:54 PM
LayB
LayB - avatar
+ 2
thanks to you all very much
21st Sep 2017, 7:00 PM
MelioCurry
MelioCurry - avatar