How does the oxidation number of oxygen changes when oxygen reacts with fluorine
Oxygen is an electronegative element
But oxygen is not the most electronegative element. It has an electro negativity of 3.5 on Pauling scale. That means if oxygen combines with an element which is more electronegative than it will surely possess a positive oxidation state.
Fluorine being the most electronegative element (electro negativity of 4.0 on Pauling scale) will in any case (except in fluorine gas) have an oxidation state of -1. So that's the reason why oxygen has a +2 oxidation state in OF2.
Dioxygen difluoride (O2F2) is another fluoride of oxygen in which oxygen has an oxidation state of +1.
Fluorine in its gaseous form (F2) has zero oxidation state.