+ 1
Python String question.
Question is: x = 9 y = "2" print (str(x)+y) Solution: 92 -A string must be surrounded by either single or double quotes? So shouldn't the answer just be "2"?
3 Respostas
+ 10
print(str(x) + y)
str(x) turns x into a string, so it becomes '9'. Now, since both str(x) and y are strings, the '+' is interpreted as the string concatenation operation. '9' + '2' = '92', which is the output (when printing just a string the quotes are omitted).
Hope that helps. 😊
+ 3
You're welcome, tristach605 👍
+ 2
Huge help! Thanks Saha!