Why does for loop iteration returns only the first character of a string?

Why does this function return only the first character of the string instead of iterating all through the string??

return immediately leaves the currently executing function and returns the given value. If you want all the values, you can (depending on what you need):

  • Gather the tuples in a list.
  • Turn the function into a generator function by using yield instead of return, and iterate over it.

Thanks a lot. I get it now.

1 Like