t1 = ()
t2 =(1,) # 튜플타입의 데이터를 1개만 생성할 경우 [,] 사용해야함(필수)
t2_1 =(1) # 콤마가 없을경우 int 타입
print(type(t2), type(t2_1))
t3 = (1,2,3,4,5)
t4 = 1,2,3,4,5 # 튜플임 ( ) 생략가능 / 리스트는 [] 꼭 써야함
print(type(t4))
<class 'tuple'> <class 'int'>
<class 'tuple'>
t5 = (1,2,3,'a','b')
t6 = (1,2,3,'a','b',(1,2,3,4),[1,2,3,5])
print(t6)
print(t6[6][1])
t6[6][1] = 10
print(t6)
(1, 2, 3, 'a', 'b', (1, 2, 3, 4), [1, 2, 3, 5])
2
(1, 2, 3, 'a', 'b', (1, 2, 3, 4), [1, 10, 3, 5])
print("t3",t3)
print(t3[2]) # 데이터 사용가능 (인덱싱 가능)
print(t3[2:3]) # 슬라이싱 가능 -> 튜플의 형태로 데이터 리턴
t3 (1, 2, 3, 4, 5)
3
(3,)
print(t3 + t4)
t5 = t3+t4
print(t5)
print(t3[0:2]+t4)
(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
(1, 2, 1, 2, 3, 4, 5)
print(t3 * 2)
print(t3[0:2] * 2)
# print(t3[0] * 2) 불가능
(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
(1, 2, 1, 2)
print("길이 : ", len(t3))
print(t3)
# t3 튜플에 6,7 추가
print(t3 +(6,7))
t3+=(8,9)
print( t3 )
길이 : 5
(1, 2, 3, 4, 5)
(1, 2, 3, 4, 5, 6, 7)
(1, 2, 3, 4, 5, 8, 9)
dic = { "name":"itwill","tel":"0518030909","addr":"부산진구" }
print(dic)
# 레퍼런스[' key값 ']
print("dic['name'] = ",dic['name'])
# 전화번호, 주소
print(dic["tel"],dic["addr"])
dic["addr"] = "부산진구 동천로109"
print(dic["addr"])
{'name': 'itwill', 'tel': '0518030909', 'addr': '부산진구'}
dic['name'] = itwill
0518030909 부산진구
부산진구 동천로109
# dic[4]="0518030979"
dic["fax"]="0518030979" # fax 키값, 0518030979 value값 저장 {"fax":"0518030979"}
print(dic)
# dic["classRoom"] = [1,2,3,4,5,6,7]
dic["classRoom"] = (1,2,3,4,5,6,7)
print(dic)
{'name': 'itwill', 'tel': '0518030909', 'addr': '부산진구 동천로109', 'fax': '0518030979'}
{'name': 'itwill', 'tel': '0518030909', 'addr': '부산진구 동천로109', 'fax': '0518030979', 'classRoom': (1, 2, 3, 4, 5, 6, 7)}
del( dic['fax'] )
print(dic)
print( type(dic) )
{'name': 'itwill', 'tel': '0518030909', 'addr': '부산진구 동천로109', 'classRoom': (1, 2, 3, 4, 5, 6, 7)}
<class 'dict'>
dic["tel"]="010-1234-1234"
print(dic)
dic2= { "k":"125455", "k":"111111"}
print( dic2["k"] )
{'name': 'itwill', 'tel': '010-1234-1234', 'addr': '부산진구 동천로109', 'classRoom': (1, 2, 3, 4, 5, 6, 7)}
111111
print( dic.keys() )
print( type(dic.keys()) ) # <class 'dict_keys'> 타입
dict_keys(['name', 'tel', 'addr', 'classRoom'])
<class 'dict_keys'>
ls = list( dic.keys() )
print( type(ls),ls )
<class 'list'> ['name', 'tel', 'addr', 'classRoom']
print(dic.values())
print( type(dic.values())) # <class 'dict_values'> 타입
dict_values(['itwill', '010-1234-1234', '부산진구 동천로109', (1, 2, 3, 4, 5, 6, 7)])
<class 'dict_values'>
print( dic.items() )
print( type(dic.items())) # <class 'dict_items'> 타입
dic.clear()
print( dic )
# print( dic['name'] ) 에러 (key값이 없기 때문)
dict_items([('name', 'itwill'), ('tel', '010-1234-1234'), ('addr', '부산진구 동천로109'), ('classRoom', (1, 2, 3, 4, 5, 6, 7))])
<class 'dict_items'>
{}
print('name' in dic )
if 'name' in dic:
print("key값이 있습니다",dic['name'])
else:
print("key값이 없습니다. (key 생성)")
dic["name"]=""
print(dic)
False
key값이 없습니다. (key 생성)
{'name': ''}
dic["tel"]="010-1234-1234"
print( dic.get("없는키") ) # 없는 key => None 리턴
print( dic.get("tel") ) # 있는 key => key에 해당하는 value를 리턴
# print( dic["addr"] ) -> key에러 발생
None
010-1234-1234
s1 = set([1,2,3,4,5])
print(s1, type(s1))
s2 = set("itwill")
print(s2,type(s2))
# print( s1[0] ) 순서가 없기 때문에 인덱싱 X
# => 리스트/튜플로 변경후 사용
l1 = list(s1)
print(l1[0])
t1 = tuple(s2)
print(t1[1])
{1, 2, 3, 4, 5} <class 'set'>
{'i', 'l', 'w', 't'} <class 'set'>
1
t
문자열 - "test" (T) , "" (F)
리스트 - [1,2] (T), [] (F)
튜플 - () (F)
딕셔너리 - {} (F)
숫자 - 0이 아닌숫자 (T), 0 (F)
None (F)
ls = [1,2,3,4]
# id(객체) -> 객체의 메모리 주소
print( ls , id(ls))
ls2 = ls
print( id(ls2), id(ls))
# A is B : A와 B가 동일한 객체 인가? 물어보는 연산자 is
print( ls is ls2 )
from copy import copy
a = copy(ls2)
print(a, id(a),id(ls2))
[1, 2, 3, 4] 2604960319936
2604960319936 2604960319936
True
[1, 2, 3, 4] 2604960380800 2604960319936
a,b = ( '1','2' )
(a,b) = ( '1','2' )
[aa,bb] =[11,22]
a=b=100
a=100
b=200
a,b = b,a
print(a,b)
200 100