jm_p_op

.py dictionary를 class에 넣기 , ** 언어 본문

py

.py dictionary를 class에 넣기 , ** 언어

jm_p_op 2023. 4. 3. 17:04
class Station:
    def __init__(self,**station):
        self.id=station.get('id')
        self.title=station.get('title')
        self.author=station.get('author')
        self.content=station.get('content')

stat={'id': "id값",
   'title':"title값",
   'author':"author값",
   'content':"content값"}
a=Station(**stat)
print(a.id)