Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python data class default value for str to None

I have a dataclass like this:

from dataclasses import dataclass

@dataclass
class DataClassCard:
    rank: str = None
    suit: str 

I am getting an error saying:

TypeError: non-default argument 'suit' follows default argument

Is there anyway to set this default value?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Finally calling:

queen_of_hearts = DataClassCard(suit = 'a')
queen_of_hearts.rank

>Solution :

Fields with a default value must come after any fields without a default. Just put suit above

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading