Set

- 단일 변수에 여러 항목을 저장하는 데 사용

- 중복의 값을 허용하지 않고 항목을 변경할 수 없음

- 항목에 정의 된 순서가 없음

thisset = {"apple", "banana", "cherry"}
print(thisset)

add로 set에 항목을 추가

thisset = {"apple", "banana", "cherry"}

thisset.add("orange") # orange 추가

print(thisset)

다른 set의 항목을 현재 set에 추가하려면 update 사용

thisset = {"apple", "banana", "cherry"}
tropical = {"pineapple", "mango", "papaya"}

thisset.update(tropical)

print(thisset)

항목 제거

- del키워드는 완전히 세트를 삭제

- remove , discard

thisset = {"apple", "banana", "cherry"}

thisset.remove("banana")

print(thisset)
thisset = {"apple", "banana", "cherry"}

thisset.discard("banana")

print(thisset)

출처

https://www.w3schools.com/python/python_sets.asp

'Python' 카테고리의 다른 글

반복문, 조건문  (0) 2021.06.17
Dictionary  (0) 2021.06.17
Tuple  (0) 2021.06.17
List  (0) 2021.06.17
Python 기초  (0) 2021.06.16

+ Recent posts