Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Pythonic For Loops

Give Feedback

In languages like C or Java, loops keep track of an index manually and increment it on every loop iteration. Loops in Python are different. Pythonic loops don’t need to keep track of an index because they can do this automatically.

This is the correct way to write for loops:

candies = ['Snicker', 'Kitkat', 'Twix', 'Mars']

for candy in candies:
    print candy

Daniel on March 21, 2019

Enjoyed the series!

Peter D K on April 1, 2019

Hello Thanks, understood and could tell you know topic in-depth. Just a little slower with presentation speed. Regards Peter

mikesult on Feb. 24, 2020

Thanks for tips on writing Pythonic code. Very helpful.

dragonfly7 on March 29, 2020

These snippets will help to produce more pythonic code !

If I#m not wrong python 2 syntax used, right ?

Become a Member to join the conversation.