0
why can't we write >>>4*'2' as 44 rather than 2222
3 Respostas
+ 3
'4'*2
+ 3
Because in your example, 4 is a literal integer value (not quoted) and '2" is a literal sring value, so this is implicit to result 2222 ^^ (as inverse mean nothing... number of repetition need to be an integer, and 'repetition' of this kind only apply to string, not number)
As suggested by @HelboTeam, to get 44, do the inverse (4 enclosed in quotes, and 2 not):
'4'*2
0
In Python, the multiplication operator (*) is overloaded. When "multiplying" an integer by a string, the answer is that string repeated as many times as the integer value. So, 4 * '2' is the string '2' repeated 4 times or '2222'. Whereas, '4' * 2 is the string '4' repeated 2 times or '44'.