์๋ฌ(Error)
๊ฐ ๋ฐ์ํ๋ค.()
๋ฅผ ์ด์ฉํด ์ ์ธํ๊ณ , ๋ฐ์ดํฐ ๊ตฌ๋ถ์ ์ฝค๋ง,
๋ฅผ ์ด์ฉํ๋ค. ์ ์ธ์ ๊ดํธ ์๋ต์ด ๊ฐ๋ฅํ๋ค.๋ฆฌ์คํธ(List)์ ๊ฐ์ฅ ํฐ ์ฐจ์ด์
โป ๋ฆฌ์คํธ(List)์ ๋น์ทํ์ง๋ง ์์ดํ
๋ณ๊ฒฝ ๋ถ๊ฐ
์ถ๊ฐํ๋ ค๊ณ ํด ๋ณด๋ฉด, ์๋ฌ(Error)๊ฐ ๋ฐ์
students = ('๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ด๋ฐ์ฌ')
numbers = (10, 20, 30, 40, 50, 60)
strs = (3.14, '์ญ', 20, 'one', '3.141592')
datas = (10, 20, 30, (40, 50, 60))
students = ('๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ')
for i in range(len(students)):
if i % 2 == 0:
print('์ง์ student No. {} : {}' .format(i, students[i]))
else:
print('ํ์ student No. {} : {}'.format(i, students[i]))
in
/not in
Keyword : ์์ดํ
์กด์ฌ ์ /๋ฌด ํ๋จstudentsTuple = ('๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ')
searchName = input('ํ์ ์ด๋ฆ ์
๋ ฅ: ')
if searchName not in studentsTuple:
print('{} ํ์์ ์ฐ๋ฆฌ ๋ฐ ํ์์ด ์๋๋๋ค.' .format(searchName))
else:
print('{} ํ์์ ์ฐ๋ฆฌ ๋ฐ ํ์์
๋๋ค.'.format(searchName))
students = ('๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ')
sLength = len(students)
print('sLength : {}' .format(sLength))
+
โ ๋ฅผ ์ด์ฉํด ๋ ๊ฐ ์ด์์ ํํ์ ๊ฒฐํฉํ ์ ์๋ค.students1 = ('์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ')
students2 = ('๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ธ๊ตญ์ธ')
students3 = students1 + students2
print(f'{students3}')
slice()
ํจ์๋ฅผ ์ด์ฉํด์ ์์ดํ
์ ์ฌ๋ผ์ด์ฑํ ์ ์๋ค.students = '์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ', '๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ธ๊ตญ์ธ'
print(f'students : {students}')
print(f'type : {type(students)}')
students = '์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ', '๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ธ๊ตญ์ธ'
listStudents = list(students)
print(f'type : {type(listStudents)}')
tupleStudents = tuple(listStudents)
print(f'type : {type(tupleStudents)}')
students = ('์ด๋ฐ์ฌ', '์ธ๊ตญ์ธ', '๋ฅํ๊ธฐ', '๊น์งํ', '์ฑ๋ฉธ์น', '์ธ๊ตญ์ธ')
print('students type : {}' .format(type(students)))
print('students : {}' .format(students))
print()
students = list(students) # ํํ > ๋ฆฌ์คํธ
students.sort()
print('students type : {}' .format(type(students)))
print('students : {}' .format(students))
print()
students = tuple(students) # ๋ฆฌ์คํธ > ํํ
print('students type : {}' .format(type(students)))
print('students : {}' .format(students))
sorted() : ํํ์์๋ ์ฌ์ฉ ๊ฐ๋ฅํ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ. ๋ฐํ๋๋ ๋ฐ์ดํฐ๋ โ๋ฆฌ์คํธโ ํ์์ด๋ฉฐ ์๋ณธ์ ์ ์ง๋จ
cars = '๊ทธ๋์ ', '์๋ํ', '์์ด์ค๋', '์๋ ํ ', '์ฝ๋'
for i in range(len(cars)):
print(cars[i])
studentsCnt = ((1, 19), (2, 20), (3, 22), (4, 18), (5, 21))
for i in range(len(studentsCnt)):
print('{}ํ๊ธ ํ์ ์ : {} ' .format(studentsCnt[i][0], studentsCnt[i][1]))
for classNo, cnt in studentsCnt:
print('{}ํ๊ธ ํ์ ์ : {} ' .format(classno, cnt))
# ๋ฐฉ๋ฒ 1
cars = ('์ฝ๋', 'ํฌ์ผ', '๊ทธ๋์ ', '์บ์คํผ', 'G70', 'G80', 'G90', '์์ด์ค๋')
n = 0
while n < len(cars):
print(cars[n])
n += 1
# ๋ฐฉ๋ฒ 2
cars = ('์ฝ๋', 'ํฌ์ผ', '๊ทธ๋์ ', '์บ์คํผ', 'G70', 'G80', 'G90', '์์ด์ค๋')
n = 0
flag = True
while flag:
print(cars[n])
n += 1
if n == len(cars):
flag = False
# ๋ฐฉ๋ฒ 3
cars = ('์ฝ๋', 'ํฌ์ผ', '๊ทธ๋์ ', '์บ์คํผ', 'G70', 'G80', 'G90', '์์ด์ค๋')
n = 0
flag = True
while True:
print(cars[n])
n += 1
if n == len(cars):
break