iterate over numbers in int python 1

iterate over numbers in int python

for c in string:
    c = int(c)
    # do stuff with c

Here is what the above code is Doing:
1. It’s taking the string “12345” and iterating over it.
2. It’s taking each character in the string and assigning it to the variable c.
3. It’s converting the character to an integer.
4. It’s doing something with the integer.

The above code is a bit clunky. It’s also not very Pythonic.

Here’s a more Pythonic way to do the same thing:

Similar Posts