Course Content
Python Loops
Python Loops
Simple For Loops
Finally, more interesting Python loops! There is another type of loops with the following syntax:
for val in list: instructions
val receives the current value from list on each iteration. This way, you don't need any stop condition in your loop and it never becomes infinite. Use for
loop for any iterable object: list, tuple, string, etc.
By the way, it is much more appropriate to iterate string using for
loop instead of while
.
string = 'You are rockstar' for sym in string: print(sym * 13)
Task
Change the given word
by skipping all spaces, like:
And I don't wanna miss a thing
-> AndIdon'twannamissathing
Use for
loop. Create new_word
for that, modify it inside the loop and output it.
Thanks for your feedback!
Simple For Loops
Finally, more interesting Python loops! There is another type of loops with the following syntax:
for val in list: instructions
val receives the current value from list on each iteration. This way, you don't need any stop condition in your loop and it never becomes infinite. Use for
loop for any iterable object: list, tuple, string, etc.
By the way, it is much more appropriate to iterate string using for
loop instead of while
.
string = 'You are rockstar' for sym in string: print(sym * 13)
Task
Change the given word
by skipping all spaces, like:
And I don't wanna miss a thing
-> AndIdon'twannamissathing
Use for
loop. Create new_word
for that, modify it inside the loop and output it.
Thanks for your feedback!
Simple For Loops
Finally, more interesting Python loops! There is another type of loops with the following syntax:
for val in list: instructions
val receives the current value from list on each iteration. This way, you don't need any stop condition in your loop and it never becomes infinite. Use for
loop for any iterable object: list, tuple, string, etc.
By the way, it is much more appropriate to iterate string using for
loop instead of while
.
string = 'You are rockstar' for sym in string: print(sym * 13)
Task
Change the given word
by skipping all spaces, like:
And I don't wanna miss a thing
-> AndIdon'twannamissathing
Use for
loop. Create new_word
for that, modify it inside the loop and output it.
Thanks for your feedback!
Finally, more interesting Python loops! There is another type of loops with the following syntax:
for val in list: instructions
val receives the current value from list on each iteration. This way, you don't need any stop condition in your loop and it never becomes infinite. Use for
loop for any iterable object: list, tuple, string, etc.
By the way, it is much more appropriate to iterate string using for
loop instead of while
.
string = 'You are rockstar' for sym in string: print(sym * 13)
Task
Change the given word
by skipping all spaces, like:
And I don't wanna miss a thing
-> AndIdon'twannamissathing
Use for
loop. Create new_word
for that, modify it inside the loop and output it.