Although I know there is a built in str()
function
in python
, I'm trying to understand its logic.
def intToStr(i):
digits = '0123456789'
if i == 0:
return '0'
result = ''
while i > 0:
result = digits[i%10] + result
i = i/10
return result
what I don't get is the part in the loop
where [i%10]
.
How do I get a remainder when i
<
10
?