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

Unlock This Lesson

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

Unlock This Lesson

Pythonic For Loops

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:

Python
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 ?

Ghani on Oct. 28, 2020

Very useful but perhaps a bit too quick presentation? Many thanks!

Walid on Jan. 16, 2021

it would be more useful if we continue this series in reviewing real popular projects and evaluate their code (code reviews/walk through) also quizzes that asks us to select between which is a better code.

Become a Member to join the conversation.