If you are only going to travel one stretch or for a shorter period, it can be worthwhile to buy single tickets in Europe. Buy tickets in Europe.
If you are going to travel over a longer period and to several places, it may be worthwhile with an Interrail ticket. Read more about Interrail.