Reputation: 61
I want to know that how many parameters I can put in a class, is there any limit or if there a more handsome way for putting attributes.have a look at the code and guide me
class residential():
def __init__(self,type,capacity,location,parking,mosque,waterbackup,cctvsecure):
Upvotes: 0
Views: 48
Reputation: 16958
The maximum number of arguments for any function in Python used to be 255. Since Python 3.7, this limit has been removed.
Another novelty in Python 3.7 is the new module dataclass which simplifies the declaration of a class with multiple arguments.
For example this code:
@dataclass class InventoryItem: '''Class for keeping track of an item in inventory.''' name: str unit_price: float quantity_on_hand: int = 0 def total_cost(self) -> float: return self.unit_price * self.quantity_on_hand
Will add, among other things, a
__init__()
that looks like:def __init__(self, name: str, unit_price: float, quantity_on_hand: int=0): self.name = name self.unit_price = unit_price self.quantity_on_hand = quantity_on_hand
Upvotes: 4