Adding onto Sergio's excellent answer: There are multiple ways in which enharmonic notes (notes of essentially the same pitch with different names, such as A# and Bb) come into play, as it were. One is with respect to different tunings. Sergio's answer cites a table that concerns two tunings, equal and just.
There are in fact lots and lots of tunings, many of which involve different compromises between equal temperament and Platonic, "natural" tunings (based on integer ratios). And so you'll see various differences between enharmonic pitches, so that the F# that shows up in a D7 won't necessarily equate with the Gb that shows up in an Ab7 (even though C shows up in both chords). An instrument tuned to play the former chord may not be able to play the latter well, and vice versa.
That example highlights another way in which enharmonic notes make a difference: music theory. This has no intrinsic impact on how the note sounds; rather, they are differences in how the note is used or interpreted. A D7 chord consists of the notes D, F#, A, and C. If you were to "spell" it D, Gb, A, C, that would sound essentially the same, but it would be marked wrong on an exam, because that second pitch is not being used as a Gb, but as an F#. That D7 will typically resolve to a G chord—major or minor—and in either case, the pitch a half-step down from G is being used as the seventh or leading tone of that G scale.
This also explains some accidentals in actual music that typically mystify beginning students, such as double-sharps and double-flats. Why notate something Fx, when G sounds the same? Such a situation often arises when you have a secondary dominant: a dominant chord resolving to a chord other than the tonic. If you're writing something in B Major, say, and you have a D# Major (V/vi) resolving to g# minor (vi), that D# Major should be notated D#, Fx, A#—not D#, G, A#, even though those pitches happen to be the same, because the note that resolves to G# should be Fx, not G.
This also applies to variously altered chords. The sharp 9 and flat 13 of "the" altered dominant seventh chord (aka tritone substitution) are shifted from their natural position, so that for our good ol' D7 chord, the sharp 9 would be E#, not F, and the flat 13 would be Bb, not A#. And so on.