1) ( ) 소괄호 이용
2) 변경(수정, 삭제 등 불가)
3) () 로 선언, ','로 데이터 구분
4) 숫자, 문자(열), 논리형 등 모든 기본데이터를 저장
5) 튜플에 또다른 컨테이너 자료형 데이터 저장 가능
1) 인덱스로 조회
students[1]
2) in과 not in (검색기능!)
pythonStr = '파이썬(영어: Python)은 1991년 프로그래머인 귀도 반 로섬이 발표한 고급 프로그래밍 언어로, ' \
'플랫폼에 독립적이며 인터프리터식, 객체지향적, 동적 타이핑(dynamically typed) 대화형 언어이다. ' \
'파이썬이라는 이름은 귀도가 좋아하는 코미디 〈Monty Python\'s Flying Circus〉에서 따온 것이다.'
print('{} : {}'.format('Python', 'Python' in pythonStr)) # True
print('{} : {}'.format('python', 'python' in pythonStr)) # False
#특정 단어 필터링 걸때
wrongWord = ['쩔었다', '짭새', '꼽사리', '먹튀', '지린', '쪼개다', '뒷담 까다']
sentence = '짭새 등장에 강도들은 모두 쩔었다. 그리고 강도 들은 지린 듯 도망갔다.'
for word in wrongWord:
if word in sentence:
print('비속어: {}'.format(word))
1) len
2) len()과 반복문 이용시 아이템 조회 가능
1) 덧셈만 가능!
#실습 없으면 추가하기 : - append가 안됨.
myFavoriteNumbers = (1, 3, 5, 6, 7)
friendFavoriteNumbers = (2, 3, 5, 8, 10)
for number in friendFavoriteNumbers :
if number not in myFavoriteNumbers:
★myFavoriteNumbers += (number, )★ ★튜플화 시켜줌
1) 리스트랑 거의 동일
2) 슬라이싱해서 아이템 변경 불가
3) 리스트에 튜플 아이템으로 변경 가능
students = ['홍길동', '박찬호', '이용규', '강호동', '박승철', '김지은']
students[1:4] = ('park chanho', 'lee yonggyu', 'gang hodong')
print('students : {}'.format(students))
print(type(students))
결과 타입은 또 list
4) 변수 [ slice(2, 3) ]
1) 차이점
students = '홍길동', '박찬호' => tuple
2) 리스트와 튜플 변환
students = ['홍길동', '박찬호', '이용규', '강호동']
print(students)
print(type(students))
#튜플
students = tuple(students)
print(students)
print(type(students))
#리스트변환
students = list(students)
print(students)
print(type(students))
3) 튜플 정렬
아이템 참조하기 : list랑 동일
studentCnts = (1, 19), (2, 20), (3, 22), (4, 18), (5, 21)
for i in range(len(studentCnts)):
print('{}학급 학생수: {} '.format(studentCnts[i][0], studentCnts[i][1]))
중첩반복문..?
for classNo, cnt in studentCnts:
print('{}학급 학생수: {}'.format(classNo, cnt))
n = 0
while n < len(scores):
if scores[n][1] >= minScore :
n += 1
continue
print(scores[n][0])
n += 1 #여기도 하나 더 !
1) 키와 값 : 인덱스가 없다
2) {}을 이용해서 선언, '키:값'의 형태로 아이템 정의
2) 숫자, 문자열, 논리형 다 옴
4) 단 key : immutable(변경불가) 한 값만 올 수 있음
1)키를 이용해 vlaue 값 조회
2)존재하지 않는 키값 조회시 에러
3)변수.get('키값')
34강.
1)딕셔너리이름[키] = 값
2)이미 키-값이 있다면 변경되는 거
35강.
1)딕셔너리이름[기존키] = 값
내꺼
n = 1
while n <= 30 :
myBodyInfo['몸무게'] = round(myBodyInfo['몸무게'] - 0.3, 2)
print('몸무게: ', myBodyInfo['몸무게'])
myBodyInfo['신장'] = round(myBodyInfo['신장'] + 0.001, 3)
print('신장: ', myBodyInfo['신장'])
myBMI = myBodyInfo['몸무게'] / (myBodyInfo['신장'] ** 2) #한번더 업뎃
n +=1
print(print(f'myBodyInfo: {myBodyInfo}'))
print(f'myBMI: {round(myBMI, 2)}')
#정답
#1
date = 0
while True:
date += 1
#3
myBodyInfo['몸무게'] = round((myBodyInfo['몸무게'] - 0.3), 2)
print('몸무게: ', myBodyInfo['몸무게'])
myBodyInfo['신장'] = round((myBodyInfo['신장'] + 0.001), 3)
print('신장: ', myBodyInfo['신장'])
#공식 한번 업데이트
myBMI = myBodyInfo['몸무게'] / (myBodyInfo['신장'] ** 2)
#2
if date >= 30:
break
36강.
1) ★변수.keys(), 변수.values()
2) ★변수.itmes() : (키, 값) 튜플 형태로 출력
3) for문과 함께 출력, enumerate
37강.
1) del 변수[key값] : 삭제하고 끝
2) ★ 변수.pop[키값] : 함수 > 데이터 반환
returnValue = memInfo.pop('이름')
print(f'memInfo: {memInfo}')
print(f'returnValue: {returnValue}') > 홍길동 반환
print(f'returnValue type: {type(returnValue)}')
38강.
1) 키의 존재 여부 판단
'키값' in 변수 / '키값' not in 변수
2) len('변수') : 딕셔너리 길이(아이템 개수)
3) 변수.clear() :