Python, append a class creation to a list a the same time

Viewed 79

I want to create a list whilst a the same time create an object The class object is the following

class Kanji:
    def __init__(self, kanji, trans, reading, words):
        self.kanji= kanji
        self.trans= trans
        self.reading= reading
        self.words = words

And I want to create the object whilst adding it to the list, like so:

lista.append(ひ = Kanji("火","fire",["ひ","び","ほ","か"],"Sample Text"))

But the following error pops up

TypeError: append() takes no keyword arguments

How could i do it?

1 Answers

Don't assign to new variable

lista.append(Kanji("火","fire",["ひ","び","ほ","か"],"Sample Text"))

enter image description here

Related