HappyCoding/happy python

    꼭 알아야하는 tuple

    about tuple dict {}, list [] tuple -> () 소괄호사용 list 처럼 순서가 정해져 있어 index로 값 가져올 수 있다. tuple 값의 수정과 삭제가 불가능. 튜플 만들기 tuple1 = (1,2,3) tuple2 = 1, 2, 3 list = [1, 2, 3] tuple3 = tuple(list)packing vs unpacking 하나의 변수에 여러개의 변수 대입 가능 packing 하나의 변수에 여러개의 값을 넣는 것 #변수 d, e를 f에 packing f = d,e unpacking 패킹된 변수에서 여러개의 값을 꺼내오는 것 #c의 값을 unpacking, d,e에 넣어줌 c = (3, 4) d, e = c튜플의 활용 1. 두 변수의 값을 바꿀 때 임시변수가 필요..

    꼭 알아야하는 list와 dictonary

    list와 dictionary 공통점 생성, 호출, 삭제, 개수확인, 값 확인, 전부 삭제 차이점 삭제 list: 삭제시 순서가 바뀌기 때문에, index값도 바뀜 dictionary : key로 값을 가져오기 때문에, 삭제 여부와 상관없다. 결합 list: list1 + list2 dictonry : dict1.update(dict2) 공통점 예 1. 생성, 호출 list = [1,2,3,4,5] dict = {'one':1, 'two':2} 2. 삭제하기 del(dict['one']) print(dict) #{'two': 2} 3. 원소 값 확인 print(2 in list) #boolean print('two'in dict.keys()) print('three'in dict.keys()) print..

    꼭 알야아하는 list, dict

    빠르게 정리하는 PYTHON 기초 매개변수 def add(a,b): result = a+b print( "{} + {} = {}".format(a,b,result) ) add(10,5)str.format() name = 'Ellie' color = 'yellow' print('안녕하세요. 제 이름은 {}이고 좋아하는 색은 {}입니다.'.format(name,color))리스트에 새로운 값을 추가하는 방법 list1 = [1, 2] list1.append(3) list2 = list1+[4] list3 = list1 + list2리스트에서 값을 지우는 방법 del list1[10] list1.remove(2)enumerate 리스트가 있는 경우 순서와 리스트의 값..