list은 정렬되고 변경 가능한 모음. 중복 회원을 허용.
tuple은 정렬되고 변경할 수 없는 컬렉션. 중복 회원을 허용.
set은 순서가 지정되지 않고 변경 불가능하며 인덱싱되지 않은 콜렉션. 중복 회원 허용 안함.
dictionary는 정렬되고 변경 가능한 모음. 중복 회원 허용 안함.
- 순서가 지정되고 변경이 가능하다.
- 중복값을 허용한다.
- 모든 데이터 유형을 허용한다.
- 대괄호로 작성된다.
Python의 관점에서 list는 데이터 유형이 'list'인 객체로 정의됨
<class 'list'>//예시코드 thislist = ["apple", "banana", "cherry"] //직접 선언 thislist = list(("apple", "banana", "cherry")) // 생성자로 선언
- 순서가 지정되며 변경을 허용하지 않는다.
-> 순서 및 값 변경 x, 값 추가 및 제거 x- 둥근 괄호로 작성된다.
- 중복을 허용한다.
파이썬의 관점에서 튜플은 데이터 유형이 '튜플'인 객체로 정의됨
<class 'tuple'>//예시코드 thistuple = ("apple", "banana", "cherry", "apple", "cherry") thistuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets
항복이 하나인 튜플을 생성하기 위해선 항목 뒤에 ',' 를 추가해야한다. 그렇지 않으면 파이썬이 튜플로 인식하지 못함
thistuple = ("apple",)
print(type(thistuple)) //<class 'tuple'>
#NOT a tuple
thistuple = ("apple")
print(type(thistuple)) //<class 'str'>
tuple1 = ("abc", 34, True, 40, "male")
print(tuple1) //('abc', 34, True, 40, 'male')
- 정렬되지 않는다.
- 변경이 불가능하다.
- 순서가 지정되지 않는다(색인화 되지 않는다)
-> 사용할때마다 다른 순서로 나타날 수 있으며, 인덱스나 키로 참조할 수 없다.- 중복이 불가능하다.
thisset = {"apple", "banana", "cherry", "apple"} print(thisset) //{'banana', 'cherry', 'apple'}
- 모든 데이터 유형이 포함될 수 있다.
Python의 관점에서 집합은 데이터 유형이 'set'인 개체로 정의
<class 'set'>//예시코드 thisset = {"apple", "banana", "cherry"} thisset = set(("apple", "banana", "cherry")) # note the double round-brackets
//중복값은 기존값을 덮어 쓴다.
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964,
"year": 2020
}
print(thisdict) //{'brand': 'Ford', 'model': 'Mustang', 'year': 2020}
Python 버전 3.7부터는 사전이 정렬 됩니다. Python 3.6 및 이전 버전에서는 사전이 정렬되지 않았습니다.
Python의 관점에서 사전은 데이터 유형이 'dict'인 객체로 정의
<class 'dict'>//코드 예시 thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict = dict(name = "John", age = 36, country = "Norway") print(thisdict)