๐ ์๋ฃ๊ตฌ์กฐ๋?
- List, Tuple, Dic, Set ์ผ๋ก ๊ตฌ๋ถ๋์ด์ง๋ค.
- List - ์์ ๋ฐ์ดํฐ๋ฅผ ์ธ์ ๋ ์ง ๋ฐ๊ฟ ์ ์๋ค.
- Tuple : ๋ฐ์ดํฐ๊ฐ ์ ํด์ง๋ฉด ๋ฐ๊ฟ ์ ์๋ค.
- Dic : key / value๋ก ์๋ฃ๊ตฌ์กฐ๊ฐ ์ด๋ค์ ธ ์๋ค.
- Set : ์ค๋ณต๋ ๋ฐ์ดํฐ๊ฐ ํ์ฉ๋์ง ์๋๋ค.
๐ ๋ฆฌ์คํธ๋? (List)
- []๋ฅผ ์ด์ฉํ์ฌ ์ ์ธํ๊ณ , ๋ฐ์ดํฐ ๊ตฌ๋ถ์ ','๋ฅผ ์ฌ์ฉํ๋ค.
- ๋ฆฌ์คํธ์ ๋ ๋ค๋ฅธ ์ปจํ ์ด๋ ์๋ฃํ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ์ ์๋ค.
๐ ์ธ๋ฑ์ค (Index)
- ์์ดํ
์ ์๋์ผ๋ก ๋ถ์ฌ๋๋ ๋ฒํธํ
- ์์๋ 0๋ถํฐ ์์ํ๋ค.
- ๋ฆฌ์คํธ ์์ดํ ์ ์ธ๋ฑ์ค๋ฅผ ์ด์ฉํ์ฌ ์กฐํ๊ฐ ๊ฐ๋ฅํ๋ค.
๐ ์์ดํ ๊ฐ์
- ๋ฆฌ์คํธ ๊ธธ์ด = ๋ฆฌ์คํธ์ ์ ์ฅ๋ ์์ดํ ๊ฐ์
- len()๊ณผ ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํ์ฌ, ์์ดํ ์กฐํ๊ฐ ๊ฐ๋ฅํ๋ค.
myFavoriteSports = ['์์', '๋ฐฐ๊ตฌ', '์ผ๊ตฌ', '์กฐ๊น
']
for i in range(4):
print(f'myFavoriteSports[{i}] : {myFavoriteSports[i]}')
print()
for i in range(len(myFavoriteSports)):
print(f'myFavoriteSports[{i}] : {myFavoriteSports[i]}')
print()
for item in myFavoriteSports:
print(item)
>>
myFavoriteSports[0] : ์์
myFavoriteSports[1] : ๋ฐฐ๊ตฌ
myFavoriteSports[2] : ์ผ๊ตฌ
myFavoriteSports[3] : ์กฐ๊น
myFavoriteSports[0] : ์์
myFavoriteSports[1] : ๋ฐฐ๊ตฌ
myFavoriteSports[2] : ์ผ๊ตฌ
myFavoriteSports[3] : ์กฐ๊น
์์
๋ฐฐ๊ตฌ
์ผ๊ตฌ
์กฐ๊น
๐ ๋ฆฌ์คํธ์ for๋ฌธ
- for๋ฌธ์ ์ด์ฉํ๋ฉด, ๋ฆฌ์คํธ์ ์์ดํ ์ ์๋์ผ๋ก ์ฐธ์กฐํ ์ ์๋ค.
studentsCnts = [[1, 19], [2, 20], [3, 22], [4, 18], [5, 21]]
for i in range(len(studentsCnts)):
print('{}ํ๊ธ ํ์ ์ : {}'.format(studentsCnts[i][0], studentsCnts[i][1])) #ํท๊ฐ๋ฆฌ๊ธฐ ์ฌ์!
print()
for classNo, cnt in studentsCnts:
print('{}ํ๊ธ ํ์ ์ : {}'.format(classNo, cnt))
studentsCnts = [[1, 18], [2, 19], [3, 23], [4, 21], [5, 20], [6, 22], [7, 17]]
sum = 0
for classNo, cnt in studentsCnts:
print('{}ํ๊ธ ํ์ ์ : {}'.format(classNo, cnt))
sum += cnt
print('์ ์ฒด ํ์ ์ : {}'.format(sum))
print('ํ๊ท ํ์ ์ : {}'.format(int(sum / len(studentsCnts))))
๐ Item ํค์๋์ List
minScore = 60
scores = [['๊ตญ์ด',58],
['์์ด',77],
['์ํ',89],
['๊ณผํ',99],
['๊ตญ์ฌ',50]]
for item in scores:
if item[1] < minScore:
print('๊ณผ๋ฝ ๊ณผ๋ชฉ : {}, ์ ์ {}'.format(item[0], item[1]))
print()
for subject, score in scores:
if score < minScore:
print('๊ณผ๋ฝ ๊ณผ๋ชฉ : {}, ์ ์ {}'.format(subject, score))
print()
for subject, score in scores:
if score >= minScore: continue
print('๊ณผ๋ฝ ๊ณผ๋ชฉ : {}, ์ ์ {}'.format(subject, score))
studentCnts = [[1, 18], [2, 19], [3, 23], [4, 21], [5, 20], [6, 22], [7, 17]]
minclassNo = 0; maxclassNo = 0
minCnt = 0; maxCnt = 0
for classNo, cnt in studentCnts:
if minCnt == 0 or minCnt > cnt:
minclassNo = classNo
minCnt = cnt
if maxCnt < cnt:
maxclassNo = classNo
maxCnt = cnt
print('ํ์ ์๊ฐ ๊ฐ์ฅ ์ ์ ํ๊ธ(ํ์์): {}ํ๊ธ({}๋ช
)'.format(minclassNo, minCnt))
print('ํ์ ์๊ฐ ๊ฐ์ฅ ๋ง์ ํ๊ธ(ํ์์): {}ํ๊ธ({}๋ช
)'.format(maxclassNo, maxCnt))
๐ enumerate()
sports = ['๋๊ตฌ', '์๊ตฌ', '์ถ๊ตฌ', '๋ง๋ผํค', 'ํ
๋์ค']
for i in range(len(sports)):
print('{} : {}'.format(i,sports[i]))
print()
for idx, value in enumerate(sports): #idx, value๋ก ๊ฐ์ ๋ฐ์ ์ ์๋ค.
print('{} : {}'.format(idx,value))
>>>>>>>>
0 : ๋๊ตฌ
1 : ์๊ตฌ
2 : ์ถ๊ตฌ
3 : ๋ง๋ผํค
4 : ํ
๋์ค
0 : ๋๊ตฌ
1 : ์๊ตฌ
2 : ์ถ๊ตฌ
3 : ๋ง๋ผํค
4 : ํ
๋์ค
๐ insert()
- ํน์ ์์น(index)์ ์์ดํ ์ ์ถ๊ฐํ ์ ์๋ค.
numbers = [1, 3, 6, 11, 45, 54, 62, 74, 85]
inputNumber = int(input('์ซ์ ์
๋ ฅ : '))
insertIdx = 0
for idx, number in enumerate(numbers):
print(idx, number) #์์ดํ
์ ์์ฐจ์ ์ผ๋ก ์ถ๋ ฅํ๋ค.
if insertIdx == 0 and inputNumber < number: #ํด๋น ์ธ๋ฑ์ค์ ์ซ์๊ฐ์ด ์
๋ ฅํ ์ซ์๋ณด๋ค ํฌ๋ค๋ฉด
insertIdx = idx #insertIdx๋ ํด๋น ์ธ๋ฑ์ค ๊ฐ์ด ๋๋ค.
numbers.insert(insertIdx, inputNumber)
print(numbers)
>>
์ซ์ ์
๋ ฅ : 30
0 1
1 3
2 6
3 11
4 45
5 54
6 62
7 74
8 85
[1, 3, 6, 11, 30, 45, 54, 62, 74, 85]
๐ pop()
- pop ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ธ๋ฑ์ค์ ๊ฐ์ ๋ฐํํ ์ ์๋ค.
playerScore = [9.5, 8.9, 9.2, 9.8, 8.8, 9.0]
print('playerScore : {}'.format(playerScore))
minScore = 0; maxScore = 0
minScoreIdx = 0; maxScoreIdx =0
for idx, score in enumerate(playerScore):
if idx == 0 or minScore > score:
minScoreIdx = idx
minScore = score
print('minScore : {}, minScoreIdx : {}'.format(minScore, minScoreIdx))
playerScore.pop(minScoreIdx)
print('playerScore : {}'.format(playerScore))
for idx, score in enumerate(playerScore):
if maxScore < score:
maxScore = score
maxScoreIdx = idx
print('maxScore : {}, maxScoreIdx : {}'.format(maxScore, maxScoreIdx))
playerScore.pop(maxScoreIdx)
print('playerScore : {}'.format(playerScore))
>>
playerScore : [9.5, 8.9, 9.2, 9.8, 8.8, 9.0]
minScore : 8.8, minScoreIdx : 4
playerScore : [9.5, 8.9, 9.2, 9.8, 9.0]
maxScore : 9.8, maxScoreIdx : 3
playerScore : [9.5, 8.9, 9.2, 9.0]
๐ remove()
- remove ํจ์๋ฅผ ์ด์ฉํ์ฌ, ํน์ ์์ดํ ์ ์ญ์ ํ ์ ์๋ค.
subjects = ['๊ตญ์ด', '์์ด', '์ํ', '๊ณผํ', '๊ตญ์ฌ']
print(subjects)
removeSubject = input('remove subject : ')
while removeSubject in subjects:
subjects.remove(removeSubject)
print(subjects)
>>
['๊ตญ์ด', '์์ด', '์ํ', '๊ณผํ', '๊ตญ์ฌ']
remove subject : ์์ด
['๊ตญ์ด', '์ํ', '๊ณผํ', '๊ตญ์ฌ']
๐ extend()
- ๋ฆฌ์คํธ์ ๋ ๋ค๋ฅธ ๋ฆฌ์คํธ๋ฅผ ์ฐ๊ฒฐ(ํ์ฅ)ํ ์ ์๋ค.
- A + B = A์ ๋ํด์ง๋ค (extend)
- ๋ง์
์ฐ์ฐ์๋ฅผ ์ด์ฉํ์ฌ ๋ฆฌ์คํธ๋ฅผ ์ฐ๊ฒฐํ ์ ์๋ค.
- A + B = C, ์๋ก์ด ๋ฆฌ์คํธ๊ฐ ๋ง๋ค์ด์ง๋ค.
myFavoriteNumber = [1, 3, 5, 6, 7]
friendFavoriteNumber = [2, 3, 5, 8, 10]
print('myFavoriteNumber : {}'.format(myFavoriteNumber))
print('friendFavoriteNumber : {}'.format(friendFavoriteNumber))
addList = myFavoriteNumber + friendFavoriteNumber #๋ง์
์ฐ์ฐ์ ํ์ฉ
print('addList : {}'.format(addList))
result = []
for number in addList: #addList์ ์๋ ๊ฐ์ด
if number not in result: #๋ง์ฝ result ๋ฆฌ์คํธ์ ์๋ค๋ฉด
result.append(number) #result ๋ฆฌ์คํธ์ ๋ฐ์ดํฐ๋ฅผ appendํ๋ค.
result.sort()
print('result : {}'.format(result))
>>>
myFavoriteNumber : [1, 3, 5, 6, 7]
friendFavoriteNumber : [2, 3, 5, 8, 10]
addList : [1, 3, 5, 6, 7, 2, 3, 5, 8, 10]
result : [1, 2, 3, 5, 6, 7, 8, 10]
๐ sort()
- ์์ดํ
์ ์ ๋ ฌํ ์ ์๋ค. (๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ)
- sort(reverse = True) ๋ ๋ด๋ฆผ์ฐจ์
scores = [9.5, 8.9, 9.2, 9.8, 8.8, 9.0]
print('playerScore : {}'.format(scores))
scores.sort() #scores ๋ฐ์ดํฐ ๊ฐ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
print('playerScore : {}'.format(scores))
scores.pop(0) #๋งจ ์ฒ์ ์ธ๋ฑ์ค (์ต์๊ฐ) ๋ฐํ
scores.pop(len(scores)-1) #๋งจ ๋ท์๋ฆฌ ์ธ๋ฑ์ค (์ต๋๊ฐ) ๋ฐํ
print('playerScore : {}'.format(scores))
sum = 0
avg = 0
for score in scores:
sum += score
avg = round((sum / len(scores)), 2)
print('์ด์ : %.2f' % sum)
print('ํ๊ท : %.2f' % avg)
>>
playerScore : [9.5, 8.9, 9.2, 9.8, 8.8, 9.0]
playerScore : [8.8, 8.9, 9.0, 9.2, 9.5, 9.8]
playerScore : [8.9, 9.0, 9.2, 9.5]
์ด์ : 36.60
ํ๊ท : 9.15
๐ reverse()
secret = '27156231'
secretList = []
solvedsecret = ''
for cha in secret:
secretList.append(int(cha))
secretList.reverse()
print('secretList = {}'.format(secretList))
val = secretList[0] * secretList[1]
secretList.insert(2, val)
print('secretList = {}'.format(secretList))
val = secretList[3] * secretList[4]
secretList.insert(5, val)
print('secretList = {}'.format(secretList))
val = secretList[6] * secretList[7]
secretList.insert(8, val)
print('secretList = {}'.format(secretList))
val = secretList[9] * secretList[10]
secretList.insert(11, val)
print('secretList = {}'.format(secretList))
>>
secretList = [1, 3, 2, 6, 5, 1, 7, 2]
secretList = [1, 3, 3, 2, 6, 5, 1, 7, 2]
secretList = [1, 3, 3, 2, 6, 12, 5, 1, 7, 2]
secretList = [1, 3, 3, 2, 6, 12, 5, 1, 5, 7, 2]
secretList = [1, 3, 3, 2, 6, 12, 5, 1, 5, 7, 2, 14]
๐ ๋ฆฌ์คํธ ์ฌ๋ผ์ด์ฑ
- [n:m]์ ์ด์ฉ, ๋ฆฌ์คํธ์์ ์ํ๋ ์์ดํ ์ ๋ฝ์ ์ ์๋ค.
- [slice(n, m)] ์ผ๋ก๋ ๊ฐ๋ฅ
๐ ๋ฆฌ์คํธ์ ๊ทธ ์ธ ๊ธฐ๋ฅ
- ๋ฆฌ์คํธ๋ ๊ณฑ์ ์ฐ์ฐ์ด ๊ฐ๋ฅํ๋ค.
- index ํจ์๋ก ๋ฆฌ์คํธ์ ์ธ๋ฑ์ค๋ฅผ ์ ์ ์๋ค.
import random
lucNum = int(input('Where is lucky number 7? : '))
sampleList = random.sample(range(1, 11), 10)
sampleIdx = sampleList.index(7)
if sampleIdx == lucNum:
print('bingo!')
else:
print('false')
print('sampleList = {}'.format(sampleList))
print('sampleIdx = {}'.format(sampleIdx))
>>>>
Where is lucky number 7? : 6
false
sampleList = [8, 6, 10, 4, 9, 5, 3, 7, 2, 1]
sampleIdx = 7
๐ count()
- ๋ฆฌ์คํธ ๋ด์ ํน์ ์์ดํ ๊ฐ์๋ฅผ ์์๋ผ ์ ์๋ค.
import random
types = ['A', 'B', 'AB', 'O'] #ํ์กํ ์ ํ์ ๋ฆฌ์คํธ์ ์ ์ฅ
todayData = []
typeCnt = []
for i in range(100):
type = types[random.randrange(len(types))] #๋ฆฌ์คํธ์ ์ ์ฅ๋ ํ์กํ ์ ํ์ ๋๋ค์ผ๋ก 100๊ฐ ์์ฐ
todayData.append(type) #todayData์ append
print('todayData : {}'.format(todayData))
print('todayDataLength : {}'.format(len(todayData)))
for j in types: #types ๋ฆฌ์คํธ์ ๋ฐ์ดํฐ ๊ฐ์ j์ ํ ๋น
print('{}ํ, {}๊ฐ'.format(j, todayData.count(j)))
>>
todayData : ['B', 'O', 'A', 'AB', 'B', 'AB', 'O', 'A', 'A', 'O', 'B', 'AB', 'A', 'O', 'B', 'O', 'A', 'AB', 'O', 'O', 'AB', 'B', 'A', 'O', 'A', 'A', 'A', 'O', 'B', 'A', 'A', 'A', 'A', 'B', 'B', 'O', 'A', 'B', 'AB', 'AB', 'O', 'AB', 'AB', 'A', 'O', 'AB', 'AB', 'B', 'A', 'AB', 'A', 'B', 'B', 'AB', 'A', 'O', 'B', 'A', 'AB', 'A', 'A', 'AB', 'A', 'A', 'AB', 'A', 'A', 'O', 'A', 'AB', 'A', 'AB', 'O', 'O', 'AB', 'A', 'AB', 'AB', 'B', 'O', 'O', 'O', 'A', 'A', 'A', 'O', 'O', 'AB', 'A', 'B', 'A', 'AB', 'B', 'B', 'O', 'AB', 'O', 'B', 'A', 'O']
todayDataLength : 100
Aํ, 34๊ฐ
Bํ, 18๊ฐ
ABํ, 24๊ฐ
Oํ, 24๊ฐ
๐ del
students = ['ํ๊ธธ๋','๊ฐํธ๋', '๋ฐ์ฐฌํธ', '์ด์ฉ๊ท', '๋ฐ์น์ฒ ', '๊ฐํธ๋', '๊น์ง์']
print('students : {}'.format(students))
del students[1:4]
print('students : {}'.format(students))
>>>>>>>
students : ['ํ๊ธธ๋', '๊ฐํธ๋', '๋ฐ์ฐฌํธ', '์ด์ฉ๊ท', '๋ฐ์น์ฒ ', '๊ฐํธ๋', '๊น์ง์']
students : ['ํ๊ธธ๋', '๋ฐ์น์ฒ ', '๊ฐํธ๋', '๊น์ง์']
๐ ํํ์ด๋? (Tuple)
๐ in, not in
- in, not in ํค์๋๋ฅผ ์ด์ฉํ๋ฉด ์์ดํ ์ ์กด์ฌ ์ /๋ฌด๋ฅผ ์ ์ ์๋ค.
student = ('ํ๊ธธ๋', '๋ฐ์ฐฌํธ', '์ด์ฉ๊ท', '๋ฐ์น์ฒ ', '๊น์ง์')
studentName = input('put Name : ')
if studentName not in student:
print('{} ํ์์ ํ๊ธ์ ์์ต๋๋ค.'.format(studentName))
else:
print('{} ํ์์ ํ๊ธ์ ์์ต๋๋ค.'.format(studentName))
import random
randomNumbers = random.sample(range(1, 11), 5) #1~10๊น์ง์ ์ซ์ ์ค ๋๋ค์ผ๋ก 5๊ฐ์ ์ซ์๋ฅผ ๋ฆฌ์คํธ๋ก ๋ฐํ
userNumber = int(input('input Number : '))
if userNumber in randomNumbers: #if 5๊ฐ ์ซ์ ๋ฆฌ์คํธ์ ์
๋ ฅํ ์ซ์๊ฐ ์๋ค๋ฉด
print('bingo!')
print('random numbers : {}'.format(randomNumbers))
print('user number : {}'.format(userNumber))
else:
print('fail..')
print('random numbers : {}'.format(randomNumbers))
print('user number : {}'.format(userNumber))
>>
input Number : 5
bingo!
random numbers : [9, 4, 5, 2, 7]
user number : 5
๐ ํํ์ ๊ธธ์ด
playSports = ('์์', '๋ฐฐ๊ตฌ', '์ผ๊ตฌ', '์กฐ๊น
')
for i in range(len(playSports)):
print('myFavoriteSports[{}] : {}'.format(i, playSports[i]))
print()
for f in playSports:
print('myFavoriteSports : {}'.format(f))
print()
n=0
while n < len(playSports):
print('myFavoriteSports[{}] : {}'.format(n, playSports[n]))
n += 1
๐ ํํ์ ๊ฒฐํฉ
- ๋ง์ ์ฐ์ฐ์ ์ด์ฉ, ๋๊ฐ์ Tuple์ ๊ฒฐํฉ
- List์์ ์ฌ์ฉํ๋ extend ํจ์๋ ์ฌ์ฉ ๋ถ๊ฐ๋ฅ.
myFavoriteNum = (1, 3, 5, 6, 7)
friendFavoriteNum = (2, 3, 5, 8, 10)
print('my Favorite Num : {}'.format(myFavoriteNum))
print('friend Favorite Num : {}'.format(friendFavoriteNum))
for number in friendFavoriteNum:
if friendFavoriteNum not in myFavoriteNum:
myFavoriteNum = myFavoriteNum + (number, ) #number๋ ์๋ ์ ์ํ, ํํ๋ก ๋ณํ ํ ๋ง์
์ฐ์ฐ์ ํ์ฉ
print('my Favorite Num : {}'.format(myFavoriteNum))
>>
my Favorite Num : (1, 3, 5, 6, 7)
friend Favorite Num : (2, 3, 5, 8, 10)
my Favorite Num : (1, 3, 5, 6, 7, 2, 3, 5, 8, 10)
๐ ๋ฆฌ์คํธ์ ํํ์ ์ฐจ์ด์
- ์์ดํ ์ถ๊ฐ, ๋ณ๊ฒฝ, ์ญ์ ๋ถ๊ฐ
- ์ ์ธ ์, ๊ดํธ ์๋ต์ด ๊ฐ๋ฅ
- ๋ฆฌ์คํธ์ ํํ์ ์๋ฃํ ๋ณํ์ด ๊ฐ๋ฅํ๋ค
๐ ํํ์ ์ ๋ ฌ
- Tuple์ ์์ ์ด ๋ถ๊ฐ๋ฅ, ๋ฆฌ์คํธ๋ก ๋ณํ ํ ์ ๋ ฌ
- sorted() ํจ์๋ฅผ ์ด์ฉ, Tuple๋ ์ ๋ ฌ์ด ๊ฐ๋ฅํ๋ค.
- ๋จ, sorted()๋ ์ ๋ ฌ ํ ๋ฆฌ์คํธ ์๋ฃํ์ผ๋ก ๋ฐํ
numbers = (2, 50, 0.12, 1, 9, 7, 17, 35, 100, 3.14)
numbers = sorted(numbers)
print(numbers)
>
[0.12, 1, 2, 3.14, 7, 9, 17, 35, 50, 100]
scores = (9.5, 8.9, 9.2, 9.8, 8.8, 9.0)
print(scores) #Tuple ํ์ผ๋ก ์ถ๋ ฅ
scores = sorted(scores) #sorted ํจ์๋ก ์ ๋ ฌ ํ ๋ฆฌ์คํธ๋ก ๋ณํ, ํํ์ ๋ฐ์ดํฐ ์์ ์ด ๋ถ๊ฐ
print(scores)
scores.pop(0) #์ ๋ ฌ๋ ๋ฆฌ์คํธ์์ ์ต์๊ฐ ๋ฐํ
scores.pop(len(scores) - 1) #์ต๋๊ฐ ๋ฐํ
print(scores)
sum = 0
avg = 0
for s in scores:
sum += s
avg = sum / len(scores)
print('์ด์ : %.2f' %sum)
print('์ด์ : %.2f' %avg)
>
(9.5, 8.9, 9.2, 9.8, 8.8, 9.0)
[8.8, 8.9, 9.0, 9.2, 9.5, 9.8]
[8.9, 9.0, 9.2, 9.5]
์ด์ : 36.60
์ด์ : 9.15
๐ ํํ๊ณผ for๋ฌธ
studentCnts = (1, 18), (2, 19), (3, 23), (4, 21), (5, 20), (6, 22), (7, 17)
minClassno = 0 ; minClasscnt = 0
maxClassno = 0 ; maxClasscnt = 0
for classNo, cnt in studentCnts:
if minClasscnt == 0 or minClasscnt > cnt:
minClassno = classNo
minClasscnt = cnt
if maxClasscnt < cnt:
maxClassno = classNo
maxClasscnt = cnt
print('๊ฐ์ฅ ์ ์ ํ๊ธ : {}๋ฐ, ํ์์ : {}๋ช
'.format(minClassno, minClasscnt))
print('๊ฐ์ฅ ๋ง์ ํ๊ธ : {}๋ฐ, ํ์์ : {}๋ช
'.format(maxClassno, maxClasscnt))
>
๊ฐ์ฅ ์ ์ ํ๊ธ : 7๋ฐ, ํ์์ : 17๋ช
๊ฐ์ฅ ๋ง์ ํ๊ธ : 3๋ฐ, ํ์์ : 23๋ช
๐ ํํ๊ณผ while๋ฌธ
cars = ('๊ทธ๋์ ', '์๋ํ', '๋ง๋ฆฌ๋ถ', '์นด๋๋ฐ', '์๋ ํ ')
n = 0
while n < len(cars):
print(cars[n])
n+=1
flag = True
while flag:
print(cars[n])
n+=1
if n == len(cars):
flag = False
while True:
print(cars[n])
n+=1
if n == len(cars):
break
'Study_note(zb_data) > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํฐ๋ ๋ ธํธ (์๋ฃ๊ตฌ์กฐ ๋ฌธ์ ํ์ด)_0721 (0) | 2023.07.24 |
---|---|
์คํฐ๋ ๋ ธํธ (์๋ฃ๊ตฌ์กฐ 27~38)_0720 (0) | 2023.07.24 |
์คํฐ๋ ๋ ธํธ (๊ธฐ์ด ์ํ ๋ฌธ์ ํ์ด 31 ~ 45)_0718 (0) | 2023.07.20 |
์คํฐ๋ ๋ ธํธ (๊ธฐ์ด ์ํ 01 ~ 30)_0717 (0) | 2023.07.19 |
0713_์คํฐ๋ ๋ ธํธ (ํ์ด์ฌ ์ค๊ธ 53 ~ 65) (0) | 2023.07.17 |