>>> vowels = {'a', 'e', 'e'}
>>> vowels
{'a', 'e'}
# set method
>>> word = set('asdfqwer')
>>> word
{'e', 'd', 'a', 'w', 'r', 'f', 's', 'q'}
word = 'hello'
vowels = set('asdf')
u = vowels.union(set(word))
{'h', 'e', 'l', 'd', 'a', 'o', 'f', 's'}
d = vowels.difference(set(word))
d
{'s', 'a', 'f', 'd'}
vowels에는 포함되어 있지만 word에는 포함되어 있지 않은 객체
vowels = {'a', 'e', 'e', 'd', 'h', 'l'}
word = 'hello'
i = vowels.intersection(set(word))
{'l', 'h', 'e'}
vowels = ( 'a', 'e', 'e', 'd', 'h', 'l')
vowels = ('a', 'e', 'e', 'd', 'h', 'l')
vowels[2] = "F"
Traceback (most recent call last):
File "/Users/jayden/PycharmProjects/pythonProject2/for.py", line 3, in
vowels[2] = "F"
TypeError: 'tuple' object does not support item assignment
에러가 발생하는 것을 알 수 있다
그렇다면 변경할 수 없는 리스트를 어디에 쓸까?
자료구조의 데이터가 절대 바뀌지 않을 때 사용된다