파이썬 API 활용하기 (dotenv와 env파일) from dotenv import load_dotenvimport osload_dotenv()# API 키 가져오기API_KEY = os.getenv('API_KEY_1') .env 환경 변수 파일에API_KEY_1 = 'abcdef' 의 형식으로 변수를 설정해놓으면 된다. 그리고 API키는 노출되면 안되기 때문에 git을 사용한다면git에 .env 파일이 올라가지 않도록 .gitignore에 .env 목록을 추가한다. Python 2024.08.04
파이썬 딕셔너리 함수 (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
파이썬 appned 함수와 extend 함수 lst1 = ['apple', 'banana' , 'tomato']lst2 = ['strawberry', 'melon']lst1.append(lst2)print(lst1) >['apple', 'banana' , 'tomato', ['strawberry', 'melon']] ----------------------------------------------------------------------------------------------------------------------------------------------------****extend함수는 iterable 객체를 파라미터로 받음****lst1 = ['apple', 'banana' , 'tomato']lst2 = ['strawberry',.. 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