본문 바로가기
Python/Web Scraping

[Python] #1.2 Tuples and Dicts (#코딩공부)

by 함께 공부해요 2020. 1. 31.

https://youtu.be/98UDadllJS8

오늘도 니꼴라스쌤 강의, 정리시작!


저번에 올린 글 https://wook-2124.tistory.com/9

 

[Python] #1.1 Lists in Python

https://youtu.be/-diVnNxG2mk 오늘도 공부한 내용 정리시작!! https://wook-2124.tistory.com/8 [Python] #1.0 Date Types of Python https://youtu.be/9GYDSEMvppU 오늘부터 유튜버 Nomad Coders, 니꼴라스님의..

wook-2124.tistory.com

위 링크를 보면 tuple_((연결형)) 「…개의 요소로 된 집합」의 뜻_Sequence Types에 대해서 알 수 있었는데, 오늘은 조금만 더 깊게 들어가보자!


https://docs.python.org/3/library/

 

The Python Standard Library — Python 3.8.1 documentation

The Python Standard Library While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the opt

docs.python.org

 

https://repl.it/

 

The world's leading online coding platform

Powerful and simple online compiler, IDE, interpreter, and REPL. Code, compile, and run code in 50+ programming languages: Clojure, Haskell, Kotlin (beta), QBasic, Forth, LOLCODE, BrainF, Emoticon, Bloop, Unlambda, JavaScript, CoffeeScript, Scheme, APL, Lu

repl.it

오늘의 준비물도 저번과 동일~


1. print(type(days)) - tuple_((연결형)) 「…개의 요소로 된 집합」의 뜻_Sequence Types

저번과 동일한 내용 한번 더 복습!!

 

tuple은 "__", "__" 처럼 비슷하게 적어도 묶이지만 ("__", "__") 처럼 ()을 이용해서 묶게되면 tuple로 묶이는 것을 알 수 있다. (아래 사진 참고!)

이렇게 tuple은 두 가지로 표현을 할 수 있는데 보통은 ()을 써서 묶어주면 된다!


2. {} - Dictionary, () - Tuple, [] - List

{} 안에 있는 것들은 Dictionary(사전)에 해당되고, 그 안에 "___"은 String(문자열)이 되고, 27은 숫자, True는 Boolean, 그리고 [] 안에 있는 Kimchi와 Chicken이 List에 해당된다!!


Dictionary안에 있는 name을 검색하면 오른쪽 터미널에 나오는 것과 같이 입려해둔 "Wook" 이 나오는 것을 볼 수 있다!! 정말 마치 사전 안에 입력된 수치를 끄집어내는 듯하다..


Dictionary안에 있는 fav_food 검색하면 [] - List에 연결된 Kimchi와 Chicken이 나오는 것을 알 수 있다!


3. Dictionary에 새로운 사항 추가하기

wook["Man"] = True 인 Boolean을 추가한 것을 알 수 있다.

여기서 wook("Man")이나 wook{"Man"}으로 추가하려해봤지만, 다 에러가 떳다..

 

Dictionary - {}에 새로 집어넣으려면 [] - List를 이용해서 집어넣어야 하는 것 같다!


오늘은 짧게 정리하고 쉬러갑니다..!! 다들 우한폐렴(신종코로나바이러스) 조심하세요!!! :)

댓글