python datatype (dict, list)

Published by onesixx on

Number vs. String

Int, float, complex vs. 문자열

Built-in Collections

{set} vs. {: Dictionary}

SetDictionary
key값만 있지만 key,value 값이 있다.
가변(mutable) 리스트형– key값은 immutable(변경 불가)형식이어야 하고,
– value값은 mutable(변경 가능) 형식도 가능하다
unordered collection of dataunordered collection of data
that stores data in key-value pairs.


(Tuple) vs. [List]

TupleList
immutable mutable
수정이 불가능하다.
an ordered collection of data.
수정이 가능함 (ex. list.append() )
collection of ordered data.

Immutable vs. Mutable

 변수가 담고 있는 object의 속성에 따라 결정

Immutable mutable
int, float, bool,
string,
tuple
list, dictionary

 json vs. dictionary

json과 dictionary 모두 KEYVALUE인데 왜 굳이 json 일까

Dictionary JSON
Data StructureData Format
key는 어떤거든지…
(key기본값 없음)
key는 항상 String
(key기본값 undefined)
True/ False / Nonetrue/ false/ null
import json

dictVal = {'name':'johnDou', 'age':16, 'job':True}

jsonVal = json.dumps(dictVal)
# '{"name": "johnDou", "age": 16, "job": true}'

dictVal2 = json.loads(jsonVal)
# {'name': 'johnDou', 'age': 16, 'job': True}

dictVal['name']
# 'johnDou'
jsonVal['name']
# TypeError: string indices must be integers 
Categories: Python Basic

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x