The derivative is defined as a limit, usually written as
And for a limit to exist at a point, the limit must be the same regardless of how you approach . In this case you have going to zero from below and going to zero from above (the left and right hand limits). This also gives you the reason why technically speaking, the derivative is undefined at end-points - because the function is not defined beyond. However, there is a way around it. On the end-points, you can consider a one-handed limit for the derivative. It makes sense, because the only information about the function is on one side of the point and it doesn't matter what happens on the other side. So, for an end-point on the left, you'll have to approach from the right, and vise versa.
You'll need to clarify with (presumably) your teacher what kind of limits are considered in the making of this example.