GeeKee's Odyssey

GeeKee's Odyssey

Day 05

Photo by Clay Banks on Unsplash

Day 05

looping

gayatri kumar's photo
gayatri kumar
·Jul 5, 2022·

1 min read

Table of contents

  • for in loop
  • Project - Password Generator!

Loops do repetitive tasks for you.

for in loop

The easiest way to iterate through a list or string.


for iterator_variable in list:
  do_something()

for-in with range


upper_limit = 5
for i in range(0, upper_limit):
  print(i)

#0
#1
#2
#3
#4

for-in over a list


my_list = ['dog', 'cat', 'panda', 4, 1, 'dolphin', 9]
for ele in my_list :
  print(ele)

#dog
#cat
#panda
#4
#1
#dolphin
#9

Iterating over index


my_list = ['dog', 'cat', 'panda', 4, 1, 'dolphin', 9]
for index in range(len(my_list)) :
  print(my_list[index])

#dog
#cat
#panda
#4
#1
#dolphin
#9

Project - Password Generator!

05-op.png

05-ip.png

05-ip2.png

 
Share this