Why do you need to use the function 'str' in the following code?
I am trying to count the sum of digits in a number.
My code
for i in number:
sum(map(int, str(i))
where number is the following array
[7,79,9]
I read my code as follows
- loop though the array such that
- count sum of the integer digits
- by getting given digits in a number by map increasingly
- such that each object (given number) is converted to String // This does not make sense
Manual says this for str
Type: type
Base Class: <type 'type'>
String Form: <type 'str'>
Namespace: Python builtin
Docstring:
str(object) -> string
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.