본문 바로가기
728x90
반응형

IT관련/Python37

[확고의 쓱~ 훑어보는 기록] Python - dict 사전 예제(4) (enumerate함수, 영단어장 만들기) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #-*- coding:utf-8 ''' Created on 2022. 7. 28. @author: hwakgo ''' d = {'오뚜기':100,'농심':100,'삼양':100} for i in d : print(i, end=' ') #▶오뚜기 농심 삼양 print() #★ dict함수 7 - enumerate() : 열거형 데이터를 처리하는 함수 for i in enumerate(d) : print(i, end=' '.. 2022. 7. 29.
[확고의 쓱~ 훑어보는 기록] Python - dict 사전 예제(3) (for문 이용해서 key와 value값 가져오기) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #-*- coding:utf-8 ''' Created on 2022. 7. 28. @author: hwakgo ''' score = {'우변':100,'봄날의햇살최수연':1004} print(score.keys())#▶dict_keys(['우변', '봄날의햇살최수연']) print(score.values())#▶dict_values([100, 1004]) #dict의 key값만 반복해서 가져오기(dict의 keys함수 활용) for k in score.keys() : print(k, end=' ')#▶우변 봄날의햇살최수.. 2022. 7. 28.
[확고의 쓱~ 훑어보는 기록] Python - dict 사전 예제(2) (데이터 확인, dict함수(get, update, clear)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #-*- coding:utf-8 ''' Created on 2022. 7. 28. @author: hwakgo ''' score = {'방구뽕':100,'우투더영투더우':1000} print(score)#▶{'방구뽕': 100, '우투더영투더우': 1000} #우변 점수 갖고오기 print(score['우투더영투더우'])#▶1000 #★ dict함수 4 - get(키) : value 값을 가져옴, dict에 없는 키를 넣으면 None print(score.get('우투더영투더우'))#▶1000 print.. 2022. 7. 28.
[확고의 쓱~ 훑어보는 기록] Python - dict 사전 예제(1) (생성/추가/변경, dict함수(keys, values, items)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 #-*- coding:utf-8 ''' Created on 2022. 7. 28. @author: hwakgo ''' #★ dict 정의 : 사전. dictionary의 줄임말. java의 HashMap(key,value)과 비슷하게 .. 2022. 7. 28.
728x90
반응형