It depends on the context: the class size and style.
If it’s a graduate seminar of 8 students, then you should certainly tell the instructor. If it is a calculus lecture of 300 students, then this will not be expected at all, and might be seen as a waste of time. Unless of course there is a test in the class, or a record of attendance taken.
It’s hard to draw an exact line, but a good rule of thumb is perhaps: will your absence either affect how the instructor teaches, or go on record somehow? If the former is the case (as in a small class with a lot of interaction), then advance warning will be appreciated by the instructor. (If this is borderline, then it would be courteous but not necessary to let them know.) If the latter, then for the sake of your place on the record, you should give the explanation.
And of course, if the instructor has said anything specific about attendance expectations, then that trumps this general guideline!