Should the __init__() method of the Stack class check the passed limit value?

Question

In this exercise, the __init__() method accepts the limit parameter with no checks. Should the value for limit be checked?

Answer

It is good practice to check passed values to ensure that the values are within reasonable ranges. For example, if a Stack is created and the limit value provided is a negative number, no items can be added to the Stack. A reasonable check in the __init__() method could examine the value of the passed limit and if the value was less than or equal to 0, use the default of 1000.