100k views
3 votes
Class Sales:
id = 0
Write the setters and getters for the data member (python)

1 Answer

3 votes

Answer: A getter function returns an instance variable and a setter method mutates an instance variable

Step-by-step explanation:

class Sales:
id: int = 0

def getID(self) -> int: return self.id

def setID(self, num: int): self.id = num

The getter function, getID(), outputs the current state of id

The setter function, setID(), is used to change the value of id

User Stakolee
by
8.2k points