# 정수형
a = 1
print(a, type(a))
# 1 <class 'int'>
# 실수형
b = 1.0
print(b, type(b))
# 1.0 <class 'float'>
문자형 -> str(), '', "", '''''', """"""
"파이썬은 0부터 숫자를 센다."
문자열 인덱싱, 슬라이싱
# 문자형
a = '1'
print(a, type(a))
# 1 <class 'str'>
# 문자형 자료형 다양한 함수 활용
example = 'Life is too short, You need Python'
# 인덱싱, 슬라이싱
print(example[0])
# 'e'
print(example[-4:])
# 'thon'
print('example[3] :' ,example[3],', example.split(' ')[3] :' , example.split(' ')[3])
# example[3] : e , example.split()[3] : short,
# split 함수 활용
print("a b c a b c".split(" "))
# ['a', 'b', 'c', 'a', 'b', 'c']
print(example.split(' '))
# ['Life', 'is', 'too', 'short,', 'You', 'need', 'Python']
# replace 함수 활용
a = "Life is too short"
a.replace("Life", "Your leg")
# "Your leg is too short"
# strip 함수 활용
a = " hi "
print('왼쪽 공백 제거 : ', a.lstrip(),', 오른쪽 공백 제거 : ',a.rstrip(),', 양쪽 공백 제거 : ',a.strip())
# 왼쪽 공백 제거 : hi , 오른쪽 공백 제거 : hi , 양쪽 공백 제거 : hi
# join 함수 활용
print(",".join('abcd'))
# 'a,b,c,d'
# 리스트 생성
test_lst=[1,2,3]
print(test_lst, type(test_lst))
# [1, 2, 3] <class 'list'>
# 인덱싱
test_lst[1]
# 2
indexing_lst = [1, 2, ['a', 'b', ['Life', 'is']]] # Life 만 꺼낸다면 ?
# 슬라이싱
test_lst[1:]
# [2, 3]
slicing_lst = [1, 2, 3, ['a', 'b', 'c'], 4, 5] # b,c만 꺼낸다면?
# 리스트 연산
a = [1, 2, 3]
b = [4, 5, 6]
print(a+b)
# [1, 2, 3, 4, 5, 6]
# 리스트 관련 함수 - append
a = [1, 2, 3]
a.append(4)
print(a)
# [1, 2, 3, 4]
# 리스트 관련 함수 - pop
a.pop()
# 4
a.pop(0)
# 1
print(a)
# [2, 3]
# 리스트 관련 함수 - sort, sorted
# sort
sort_lst1 = [1, 4, 3, 2]
sort_lst.sort()
print(sort_lst)
# [1, 2, 3, 4]
sort_lst2 = ['a','c','b']
sort_lst2.sort()
print(sort_lst2)
# ['a', 'c', 'b']
# sorted
sort_lst1 = [1, 4, 3, 2]
sorted(sort_lst1)
# [1, 2, 3, 4]
print(sort_lst1)
# [1, 4, 3, 2]
a = (1,2,3)
print(a, type(a))
# (1, 2, 3) <class 'tuple'>
a.append(4)
# AttributeError: 'tuple' object has no attribute 'append'
# 딕셔너리 구조
dic = {'name':'pey', 'phone':'0119993323', 'birth': '1118'}
# Key : 각각 'name', 'phone', 'birth'
# Value : 'pey', '0119993323', '1118'
print(dic, type(dict))
# {'name': 'pey', 'phone': '0119993323', 'birth': '1118'} <class 'type'>
# 딕셔너리 생성, 추가, 삭제, 조회
test_dict = {}
test_dict['a'] = 1
test_dict['b'] =2
test_dict['c'] = [1,2,3]
print(test_dict)
# {'a': 1, 'b': 2, 'c': [1, 2, 3]}
del test_dict['a']
print(test_dict)
# {'b': 2, 'c': [1, 2, 3]}
print(test_dict.keys())
# dict_keys(['b', 'c'])
for k in test_dict.keys():
print(k)
# b
# c
print(test_dict.values())
# dict_values([2, [1, 2, 3]])
print(test_dict.items())
# dict_items([('b', 2), ('c', [1, 2, 3])])
for key,value in test_dict.items():
print(key, value)
# b 2
# c [1, 2, 3]
s1 = set([1,2,3,1])
print(s1, type(s1))
# {1, 2, 3} <class 'set'>
s2 = set("Hello")
print(s2)
# {'e', 'l', 'H', 'o'}
s1 = set([1, 2, 3, 4, 5, 6])
s2 = set([4, 5, 6, 7, 8, 9])
print(s1 & s2)
# {4, 5, 6}
print(s1.intersection(s2))
# {4, 5, 6}
print(s1 | s2)
# {1, 2, 3, 4, 5, 6, 7, 8, 9}
print(s1.union(s2))
# {1, 2, 3, 4, 5, 6, 7, 8, 9}
print(s1 - s2)
# {1, 2, 3}
print(s2 - s1)
# {8, 9, 7}
print(s1.difference(s2))
# {1, 2, 3}
print(s2.difference(s1))
# {8, 9, 7}
print(1 == 1)
# True
print(2 < 1)
# False
print(bool('python'))
print(bool(''))
# True
# False
print(bool([1,2,3]))
print(bool([]))
# True
# False
print(bool(0))
print(bool(3))
# False
# True