Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python Generators with a Loop

def rev_str(my_str):
    length = len(my_str)
    for i in range(length - 1, -1, -1):
        yield my_str[i]


# For loop to reverse the string
for char in rev_str("hello"):
    print(char)
 
PREVIOUS NEXT
Tagged: #Python #Generators #Loop
ADD COMMENT
Topic
Name
3+6 =