def add_comma(number: int) -> str:
new_number, cnt = '', 0
for num in str(number)[::-1]:
if cnt == 3:
new_number += ','
cnt = 0
new_number += num
cnt += 1
return new_number[::-1]
add_comma(1200000)
'1,200,000'
The mechanics behind it is that after every 3 numbers counting from behind, you add a comma to it; you start counting from behind and not from the beginning. So the code above is the equivalent of what the f-string function does for you.
For example, let's say the number '14589012'. To add comma to this, we count the first 3 numbers till we reach the beginning of the number, starting counting from the last digit in the number:
210,
210,985,
210,985,41
Then reverse the string, we have 14,589,012
I hope it helps, just read the code and explanation slowly.