Sorry, I really don’t know how to word this question.
I’m confused about the purpose of the content in the parenthesis after def (e.g (card: str) ) and what the -> symbol is doing. What is going on. And why does one function -> point to the class name and others point to basic data types. Help
@dataclass
class Card:
suit: str
rank: int
def parse_card(card: str) -> Card:
return Card(card[0], int(card[1:]))
@dataclass
class Rectangle:
length: int
width: int
def area(rect: Rectangle) -> int:
return rect.length * rect.width
@dataclass
class Square:
color: str
width: int
@dataclass
class Circle:
radius: int
color: str
def square_to_circle(a_square: Square) -> Circle:
return Circle(a_square.width, a_square.color)
I have no idea what I am doing please help Please
noel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.