** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
Instead of using the for statement once, try using the while statement to give an example.
while
some_list = [1, 2, 3, 4, 5]
i = 0
# i < some_Loop between the number of data contained in list
while i < len(some_list):
#i indexed some_print the elements of list
print(some_list[i])
i += 1
result
1
2
3
4
5
This is described using a for statement as follows.
for
some_list = [1, 2, 3, 4, 5]
for i in some_list:
print(i)
result
1
2
3
4
5
In this code, iterates to assign the elements contained in some_list
to i one by one.
In this way, the for statement is effective when performing iterative processing.
Of course, you can use break
and continue
in the for statement.
for
for s in 'abcde':
print(s)
result
a
b
c
d
e
for
for word in ['My', 'name', 'is', 'Tony']:
print(word)
result
My
name
is
Tony
Recommended Posts