Skip to main content

For / In

Published 1 min readMarkdown
Part of seriesPython

For and In

can be used to delete duplicated parts.

image.png

# e.g.
for individual data in range:
        Delete '안녕' from all the data

For loop

  1. : should be followed after for loop.
  2. Any loop that needs to be run repeatedly should be indented by one tab or 4 spaces. (Python doesn't run print under for if it's not indented.)

Range function

  • range(starting num, ending num)

    it does NOT include the ending number. e.g. range(0, 5) means the list of '0, 1, 2, 3, 4'

  • How many times does it run?
    • it depends on the number of individuals on the list after in.
list1 = [1, 2, 3, 4, 5]
list2 = ['a', 'b', 'c', 'd', 'e']
for element in list1: 
  print(element)

1
2
3
4
5
for element in list2:
  print(element)

a
b
c
d
e
for i in range(0, 5): # 맨 끝에 :(콜론)을 사용하였다.
  print(i,'번 반복할게요~') # print 앞에 들여쓰기를 해주었다.
0 번 반복할게요~
1 번 반복할게요~
2 번 반복할게요~
3 번 반복할게요~
4 번 반복할게요~

No comments yet. Be the first to comment.

More from this blog