all AI news
Mastering Python iteration: Loops and the magic of list comprehensions
April 8, 2024, 9:11 a.m. | MercyMburu
DEV Community dev.to
What are loops?
➰
They can be termed simply as a way to repeatedly execute some code➿.
For example:
planets= ['mercury','venus','earth','mars','jupyter','saturn','uranus','neptune']
for planet in planets:
print(planet,end='')
# The end='' overrides the \n behavior and instead adds a space ('') after each planet name
output: Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune
The for loop specifies:
The variable names to use in this case, ‘planet’
The set of values to loop over ‘planets’
You use the word ‘in’ to link …
beginners behavior code earth example iteration jupiter jupyter list lists loops magic mars mercury planet python space the end
More from dev.to / DEV Community
Jobs in AI, ML, Big Data
Data Architect
@ University of Texas at Austin | Austin, TX
Data ETL Engineer
@ University of Texas at Austin | Austin, TX
Lead GNSS Data Scientist
@ Lurra Systems | Melbourne
Senior Machine Learning Engineer (MLOps)
@ Promaton | Remote, Europe
Senior Principal, Product Strategy Operations, Cloud Data Analytics
@ Google | Sunnyvale, CA, USA; Austin, TX, USA
Data Scientist - HR BU
@ ServiceNow | Hyderabad, India