0
Why error in first?and not in the second one?
A=3 print('mom'+A) Traceback (most recent call last): File "source_file.py", line 2, in <module> print('mom'+A) TypeError: can only concatenate str (not "int") to str A=3 print('mom'*A) Output:mommommom
1 ответ
+ 2
3 is not a string, but a number. In Python you can not add a number to a string, because it's not defined.
If you want to do it, you'd first have to convert the number to a string:
print('mom' + str(A))
* on the other hand is defined for strings: It means 'gimme A times that string'.