Python 35

파이썬 딕셔너리 함수 (update, pop, del)

update 함수는 딕셔너리를 업데이트한다.해당 키가 없으면 추가하고 있으면 수정한다.my_dict = {'A': 1, 'B': 2}my_dict.update({'A': 3, 'C': 4})print(my_dict) >{'A': 3, 'B': 2, 'C': 4}----------------------------------------------------------------------------------------------------------------------------------------- pop 함수는해당 키의 키-값을 삭제하고 없으면 None을 리턴한다.my_dict = {'A': 1, 'B': 2, 'C': 3}my_dict.pop('A', None)print(my_dict) >{'B'..

Python 2024.08.04

파이썬 포맷팅 f string (f 문자열)

f문자열 내부의 변수에 대해서는 생략했음1. 함수 사용f"...{function()}"2. 소수점f"{number:.2f}"3. 1000단위 쉼표f"{number:,}"4. 공백 채우기오른쪽 정렬:  f"{char:>10}". ==> "      char"왼쪽 정렬:  f"{char:10}". ==> "char      "               (==  f"{char:가운데 정렬: f"{char:^10}" ==> "   char   "5. 특정 문자로 채우기가운데 정렬:  f"{char:-^10}". ==> "---char----"0으로 자릿수 맞추기: f"{number:04d}"6. 2진수, 8진수, 16진수f"2진수: {number:b}, 8진수: {number:o}, 16진수 소문자: {numb..

Python 2024.06.27

파이썬 클래수 변수(Class Variable)

class Account:    account_count = 0    def __init__(self, name, balance):        self.deposit_count = 0        self.deposit_log = []        self.withdraw_log = []        Account.account_count += 1    @classmethod    def get_account_num(cls):        print(cls.account_count)  # Account.account_countaccount_count는 클래수 변수이기때문에 클래스명.변수명으로 접근해야 한다.클래스 변수는 클래스를 정의한 영역에서 클래스 내부 또는 메서드 밖에 존재하는 변수이다.이는 해당..

Python 2024.06.21