Explanation:
๐น Line 1 — print()
print(...)
print() displays the final result on the screen.
๐น Step 1 — "10101"
"10101"
This is a string, containing five characters:
1 0 1 0 1
It is not being treated as a binary number here.
๐น Step 2 — map(int, "10101")
map(int, "10101")
map() applies int() to every character:
"1" → 1
"0" → 0
"1" → 1
"0" → 0
"1" → 1
So the values produced are:
1, 0, 1, 0, 1
๐น Step 3 — sum()
sum(map(int, "10101"))
sum() adds those values:
1 + 0 + 1 + 0 + 1
Result:
3
๐น Step 4 — print()
Now the complete expression becomes:
print(3)
So Python displays:
✅ Output
3

0 Comments:
Post a Comment