Choosing a transistor

I've learned about the basics of what a transistor is. But I can't find any info about how to find out which transistor to choose.

There's NPN or PNP. But what else? Gain? I can't find "gain" in any of the datasheets so far. A transistor can be used for digital switching or analog amplifying, but is a transistor best for either, or is it the same transistors?

BTW, I think I'm going to have the same question for most components. Is there a good place to find this kind of information?

I can't find "gain" in any of the datasheets so far

Give over they all have it. Look for Hfe that is the same thing.
Also look for:-
Maximum collector voltage - needs to be greater that what you are using
Maximum current - needs to be at least 20% greater than what you plan to use.
Vsat - saturation voltage, that is the collector emitter voltage when the transistor is on - this will help you calculate how hot it gets.

but is a transistor best for either, or is it the same transistors?

Same transistor.

Like Grumpy_Mike says, looking at the data sheets really help to find the info of the transistor you are using ... Like pin-out of the device, max Vc, max Ic, Hfe, max Vb, etc.

About some models, like 2N3904, 2N3906 are general purpose type, small signal amplification and general switching. They only TO-92, so Ic max is well under 200 mA. And like TIP31 and TIP32 are power type, large signal amplification, and power switching. They are TO-220, need a heatsink and the Ic max is around 2 A to 5 A. And like 2N3055 , MJ2955 are high power type, large high amplification and high power swtiching. They are TO-3, need a big heatsink and the Ic max is around 5 A to 10 A.

As for Ardiuno applications, the 2N3904 - NPN and 2N3906 - PNP for light swtiching and TIP31 - NPN and TIP32 - PNP are for high current application.

The NTE transistor selection guide is a good place to window shop transistor charateristics. You will find some have a compliment device of the opposite polarity such as the 2N3904/2N3906, also some devices will show high speed switch times whereas other will not as that function is outside the scope of their intended purpose. There are many disclaimers to NTE/SK substitution devices already outlined in print in each manual. Both manuals are also a good source of pinnout data for all the common CMOS and TTL logic IC's. Although timing information for logic IC's is not provided.