Programming Language/Python
2023.06.05
range() - range()는 iterable(이터러블)을 생성한다. - 데이터를 메모리에 보관하지 않는다. - range()의 데이터 크기는 메모리와 관계 없다. - range()는 항상 메모리가 작다. - range()는 항상 동일한 크기의 메모리를 사용한다. - range()는 반복문에서 리스트보다 빠르다. 따라서, 숫자와 관련된 반복문을 사용시에는 리스트보다 range()를 쓰자. - (Good) for i in range(5): - (Bad) for j in [0, 1, 2, 3, 4]: range()의 데이터 크기가 달라도 변수가 차지하는 메모리가 같을까? - 같다. %reset -f import sys test_range_1 = range(0, 10) test_range_2 ..
Programming Language/Python
2023.04.06
import sqlite3 con = sqlite3.connect(':memory:') cur = con.cursor() cur.execute("CREATE TABLE my_test_table(id int, name varchar, phone_number varchar);") data = [ (11, "Park", "010-1111-2222"), (12, "Kim", "010-1234-5678"), (13, "Oh", "010-8765-4321s"), ] cur.executemany("INSERT INTO my_test_table VALUES (?, ?, ?);", data) result = cur.execute("SELECT * FROM my_test_table;") for row in result: ..
Programming Language/Python
2023.04.06
import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() cur.execute("CREATE TABLE my_test_table (id int, name varchar, phone_number varchar);") cur.execute("INSERT INTO my_test_table VALUES (1, 'Park', '010-0000-0000');") cur.execute("INSERT INTO my_test_table VALUES (2, 'Kim', '010-1234-5678');") result = cur.execute("SELECT * FROM my_test_table;") for row in result: print(row) cur...
Programming Language/Python
2023.03.21
import json my_dict = {"a": "b", "c": {"d": "e", "f": "g"}} print(type(my_dict), my_dict) my_dict = json.dumps(my_dict) print(type(my_dict), my_dict) my_dict = json.loads(my_dict) print(type(my_dict), my_dict)
Programming Language/Python
2023.03.21
my_list = [0, 0, 1, 1, 2, 2] print(my_list) my_list = set(my_list) print(my_list) my_list = list(my_list) print(my_list)
Programming Language/Python
2023.03.10
from enum import Enum from fastapi import FastAPI app = FastAPI() class ModelName(str, Enum): icecream = "아이스크림" snack = "과자" chocolate = "초콜렛" @app.get( path = "/item/price", summary = "Summary", description = "Description", tags = ["Tags"], ) async def read_price(item_name: ModelName): if item_name is ModelName.icecream: price = 3000 elif item_name is ModelName.snack: price = 5000 elif item_na..
Programming Language/Python
2023.03.10
from fastapi import FastAPI app = FastAPI() @app.get( path="/items", summary="아이템 Summary 입니다.", description="아이템 Description 입니다.", tags=['First'] ) async def read_item(item_id: int, item_name: str): return {"item_id": item_id, "item_name": item_name} from fastapi import FastAPI app = FastAPI() @app.get( path="/items", summary="아이템 Summary 입니다.", description="아이템 Description 입니다.", tags=['First..
Programming Language/Python
2023.03.10
from fastapi import FastAPI app = FastAPI() @app.get( path="/items", summary="아이템 Summary 입니다.", description="아이템 Description 입니다.", ) def read_item(item_id: int, item_name: str): return {"item_id": item_id, "item_name": item_name} from fastapi import FastAPI app = FastAPI() @app.get( path="/items", ) def read_item(item_id: int, item_name: str): return {"item_id": item_id, "item_name": item_name}
Programming Language/Python
2023.03.10
from fastapi import FastAPI app = FastAPI() @app.get("/items") def read_item(item_id, item_name): return {"item_id": item_id, "item_name": item_name} from fastapi import FastAPI app = FastAPI() @app.get("/items") def read_item(item_id: int, item_name: str): return {"item_id": item_id, "item_name": item_name}
Programming Language/Python
2023.03.10
from fastapi import FastAPI app = FastAPI() @app.get("/root") def read_root(): return {"Hello": "World"} from fastapi import FastAPI app = FastAPI() @app.get("/root") def read_root(): return {"Hello": "World", "Read": "Root", "My": "Name"}