I'am new to python language. And my question is certainly a naive one and concerning python syntax.
I am at the step where I must go from theory to practice.
here is a class (a typescript one) I want to translate to python language.
class Category {
id: number;
type: 'shop'|'blog';
name: string;
slug: string;
path: string;
image: string|null;
items: number;
customFields: CustomFields;
parents?: Category[]|null;
children?: Category[]|null;
}
as python is untyped language I've got doubts about how to translate :
- the optional property : '?'
- the associated class : customFields: CustomFields;
- the arrays of associated class (that are self associated) and that are nullable : children?: Category[]|null;
I've always worked with typed language until now and it's destabilising my habits to just write nothing.
would that look like this (it's a model for django.db migration):
>from django.db import models
>>class Category(models.Model):
>>> id = models.AutoField(primary_key=True)
>>> type: 'shop'|'blog'
>>> name = models.CharField(max_length=100)
>>> slug = models.CharField(max_length=100)
>>> path = models.CharField(max_length=250)
and then ... ?
could you provide also some tuto, doc, example where you learn python in pratice ? thanks to all of you !