I've been to Yellowstone a few times. Once I even saw a bear. The last time I went looking for bear but never saw one. Although I've never hiked miles off the main trails so probably the reason I have never seen one. I would say in Yellowstone unless you are planning some good hikes, you won't have a need for bear spray. The only bear I have seen is from the car.
We sent to Glacier this past summer and that is different, there is nothing to really see from the road so you have to get out and hike to enjoy the park. We bought the 2 pack at Costco before our trip, sold locally as well as in MT. Still have some that I will keep in our trailer just in case. But, didn't need it. There was a bear sighting on one of the trails we hiked but long gone by the time we got there. Barely saw any animals on the Glacier trip, just lots of squirrels.
Bear spray is a good idea, and you should know how to use it. But in Yellowstone I think it is only necessary if you plan to hike outside the main attractions and busy areas. I don't even recall if I have ever seen people carrying bear spray in Yellowstone unlike Glacier where many people carry it.