データ構造(Python)-チュートリアル
コロイド管
튜플(Tuple)
:リストに似ているが変更不可# 튜플
students = ('강호동', '박찬호', '이용규', '박승철', '강호동', '김지은')
print(students)
print(type(students))
# students[0] = 'Test' # 변경 불가, 오류 발생
인덱스
物品照会# 인덱스
students = ('강호동', '박찬호', '이용규', '박승철', '강호동', '김지은')
print(students)
print(students[0])
print(students[1])
print(students[2])
# 오류 발생
# print('없는 인덱스 : {}'.format(students[6]))
아이템 in 튜플
:釘に物があればTrue아이템 not in 튜플
:tupleに項目がなければTrue# 아이템 존재 유무 판단
students = ('홍길동', '박찬호', '이용규', '박승철', '김지은')
searchName = input('학생 이름 입력 : ')
# in
if searchName in students:
print('in - {} 학생은 존재합니다.'.format(searchName))
else:
print('in - {} 학생은 존재하지 않습니다.'.format(searchName))
print('='*35)
# not in
if searchName not in students:
print('not in - {} 학생은 존재하지 않습니다.'.format(searchName))
else:
print('not in - {} 학생은 존재합니다.'.format(searchName))
len()
:グラフ長(アイテム数)の関数を返す# len()
students = ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
studentLength = len(students)
print(students)
print("len : {}".format(studentLength))
けつごう
+(덧셈 연산자)
:2つの継ぎ手を接続(拡張)して新しい継ぎ手に戻す# +(덧셈 연산자)
studentTuple1 = ('홍길동', '박찬호', '이용규')
studentTuple2 = ('박승철', '김지은', '강호동')
print(studentTuple1)
print(studentTuple2)
newStudents = studentTuple1 + studentTuple2
print(newStudents)
スムージング処理
[시작:종료:간격]
:スタート<=n<終了の範囲を基準に、アイテムを選択できます.# 슬라이싱
students = ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
print('1. {}'.format(students))
# 1. ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
print('2. {}'.format(students[2:4]))
# 2. ('이용규', '박승철')
print('3. {}'.format(students[2:5:2]))
# 3. ('이용규', '김은지')
# 리스트의 아이템을 튜플 형식을 사용해 바꾸는 것은 가능하다
students = ['홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동']
students[1:4] = ('park chanho', 'lee yonggyu', 'park seungcheol')
# 타입은 여전히 리스트이다.
print(students)
print(type(students))
slice(시작, 종료, 간격)
students = ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
print('1. {}'.format(students))
# 1. ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
print('2. {}'.format(students[slice(2,4)]))
# 2. ('이용규', '박승철')
print('3. {}'.format(students[slice(2,5,2)]))
# 3. ('이용규', '김은지')
リストとチュートリアル
# 리스트 추가, 변경, 삭제 가능
studnetList = ['홍길동', '박찬호', '이용규']
print(studnetList)
# 추가
studnetList.append('강호동')
print(studnetList)
# 변경
studnetList[2] = '유재석'
print(studnetList)
# 삭제
studnetList.pop()
print(studnetList)
# 튜플 추가, 변경, 삭제 불가능
studnetTuple = ('홍길동', '박찬호', '이용규')
print(studnetTuple)
# 추가 : 오류 발생
# studnetTuple.append('강호동')
# 변경 : 오류 발생
# studnetTuple[2] = '유재석'
# 삭제 : 오류 발생
# studentTuple.pop()
# 튜플 괄호
studentTuple = ('홍길동', '박찬호', '이용규')
print('type : {}, tuple : {}'.format(type(studentTuple), studentTuple))
# 튜플 괄호 생략
studentTuple = '홍길동', '박찬호', '이용규'
print('type : {}, tuple : {}'.format(type(studentTuple), studentTuple))
# 리스트 괄호
studentList = ['홍길동', '박찬호', '이용규']
print('type : {}, tuple : {}'.format(type(studentList), studentList))
# 리스트
studentList = ['홍길동', '박찬호', '이용규']
print('type : {}, tuple : {}'.format(type(studentList), studentList))
# 아이템의 값을 변경하고 싶지 않다면 튜플로 변환하면 된다.
castingTuple = tuple(studentList)
print('type : {}, tuple : {}'.format(type(castingTuple), castingTuple))
# 튜플
studentTuple = ('홍길동', '박찬호', '강호동')
print('type : {}, tuple : {}'.format(type(studentTuple), studentTuple))
# 아이템 값을 변경하고 싶다면 리스트로 변환하면 된다.
castingList = list(studentTuple)
print('type : {}, tuple : {}'.format(type(castingList), castingList))
配置
# 정렬
students = ('홍길동', '박찬호', '이용규', '강호동', '박승철', '김지은')
print(students)
# 리스트 변환
students = list(students)
# 정렬
students.sort(reverse=False)
# 튜플 변환
students = tuple(students)
print(students)
sorted()
:リストデータ型をソート関数で返す# sorted()
students = ('홍길동', '박찬호', '이용규', '강호동', '박승철', '김지은')
print(students)
newStudents = sorted(students, reverse=False)
print(newStudents)
newStudents = tuple(newStudents)
print(newStudents)
くりかえし文
1.For Moon
# for
# len()
cars = ('그랜저', '소나타', '말리부', '카니발', '쏘렌토')
for i in range(len(cars)):
print(cars[i])
# Iterable
for car in cars:
print(car)
# enumerate()
for idx, car in enumerate(cars):
print(car)
2.While文
# while
cars = ('그랜저', '소나타', '말리부', '카니발', '쏘렌토')
# len() 사용
n = 0
while n < len(cars):
print(cars[n])
n += 1
# flag 사용
n = 0
while True:
print(cars[n])
n += 1
if n == len(cars):
break
Reference
この問題について(データ構造(Python)-チュートリアル), 我々は、より多くの情報をここで見つけました https://velog.io/@skarb4788/자료구조파이썬-튜플テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol