Reputation: 21
For example the code is like
class RankingFeatureDataset(Dataset):
data: DataFrame
def __post_init__(self):
I am wondering what "data:DataFrame" do in this code. It seems it is a kind of way for constructor. Thank you.
Upvotes: 2
Views: 50
Reputation: 181
The data: DataFrame
is the type hinting syntax.
Since python is a dynamically typed language, that is, there is not an associated type with variables, type hinting is to indicate the type of the variable.
Usually it is used in function definitions, for example:
def foo(bar: int) -> int:
print(bar)
bat: int = bar + 1
return bat
bar: int
, -> int
, and bat: int = bar + 1
are all type hints. However, they are only an indication, or a “hint” as to say, so even if you pass in a variable of the “wrong” type, the code would still run.
In this case, as @kindall has said, it is to indicate that data
is of type DataFrame
. You can learn more about type hints here.
Upvotes: 3