on-internet
← Community

Using range function in Python

Stack Overflow ·

I have a question about using the range function to iterate a string. Let's say I need to capitalize everything in the following string: string = 'a b c d e f g' Can I just write the following code? for i in string: i = i.upper() return string Or should I use the range function to iterate every element in the string? Finally, a more general question is whenever I need to iterate all elements in a string/list, when should I use the range function and when can I just use the "for" loop?

Comments

Sign in or sign up to comment and upvote.

No comments yet.