
Explanation:
๐ข 1. Assigning "10" to x
x = "10"
Here, "10" is a string, not an integer.
x → "10"
type(x) → str
๐ก 2. x * 2
x * 2
Because x is a string, * 2 repeats the string.
"10" * 2
↓
"1010"
⚠️ It does not perform 10 × 2.
๐ต 3. int(x)
int(x)
The string "10" is converted into the integer 10.
"10" → 10
๐ 4. Integer Division // 2
int(x) // 2
Becomes:
10 // 2
So:
5
๐ฃ 5. str(...)
Now:
str(int(x) // 2)
converts the integer 5 back into a string:
5 → "5"
๐ด 6. Final +
The expression is now:
"1010" + "5"
Both are strings, so + performs string concatenation:
"1010" + "5"
↓
"10105"
⚡ Complete Flow
x = "10"
↓
x * 2
↓
"1010"
int("10") // 2
↓
10 // 2
↓
5
↓
str(5)
↓
"5"
"1010" + "5"
↓
"10105"
✅ Final Output
10105

0 Comments:
Post a Comment