DEV Community

Discussion on: Python Loops Cheat Sheet

Collapse
 
rhymes profile image
rhymes • Edited

Hi Shahzoda! Welcome to DEV and thanks for your first post. C++ and Python have a long standing relationship and it's nice to see new Pythonistas coming from there ;-)

A couple of tips:

IV. iterate with the indexes alone:

your example can become:

>>> arr2 = [10, 20, 30, 40, 50, 60]
>>> for i, _ in enumerate(arr2):
...     print(i)
...

also, if you add python to the ticks you can enable syntax highlighting:

syntax highlighted python block

Can't wait for you to discover list comprehensions ;-)

Collapse
 
shahzzoda profile image
Shahzoda D.

You're incredible!! Thank you for the syntax highlight tip. I learned list comprehensions already, they're really cool but the "dont care" variable is a new one too me. Really cool stuff.