Code Explanation:
๐ข 1. "5" * 2
"5" * 2
Here "5" is a string, so * 2 repeats the string two times.
"5" * 2
↓
"55"
⚠️ It does not mean 5 × 2 = 10.
๐ก 2. 5 + 2
5 + 2
Here both values are integers, so normal addition happens:
5 + 2
↓
7
๐ต 3. str(5 + 2)
Now 7 is converted from an integer into a string:
str(7)
Result:
"7"
๐ 4. Final +
The expression is now:
"55" + "7"
Both are strings, so + performs concatenation:
"55" + "7"
↓
"557"
๐ด 5. print()
Python prints the final value:
print("557")
✅ Final Output
557

0 Comments:
Post a Comment