History MattersIn many works of medieval historical fiction, medieval fantasy, or ancient historical fiction, the hero uses a sword as a primary weapon. This is regardless of whether a warrior of the culture in question would actually be likely to carry a sword at all.
There are strong cultural reasons for this trope. In Western culture, especially Northern and Central Europe, the sword is seen as the symbol of chivalry, justice, and power. The straight-bladed Middle Ages knightly sword with a simple hilt and crossguard also strongly resembles The Cross, adding religious significance to the weapon.
In Japan, the samurai is considered to be one with his katana, actually imbuing a portion of his spirit into the blade through use and sometimes manufacture. The katana symbolizes the samurai code more than any of the other weapons he could choose. Like the knightly sword in Europe, the katana in Japan is also a weapon of the nobility. Ashigaru, the common-born soldiers, could use yari spears, naginata polearms, or bows, but almost never katana.
Historically, spears were vastly more common weapons than swords. In many ancient and medieval European cultures, spears were the primary weapons of most warriors. Ancient Greece and the Saxons are two notable examples. Axes were also quite common. Both spears and axes were cheaper to make than swords, requiring less metal, and were also extremely effective in skilled hands. As armor and warfare continued to develop, maces, polearms and warhammers became more and more common.
Another reason not to use a sword is that they were often prohibitively expensive throughout history. As mentioned, any Blade on a Stick or axe-type weapon was far cheaper. So when the Hero is a Farm Boy, it's extremely unlikely that he'd have the money to buy a sword or for his relatives to pass one down to him. Of course, he might have received one for a host of reasons, all boiling down to the fact that he's The Hero, so he'd better have a sword.
On the other hand, it is possible to exaggerate how rare and valuable swords were, when in fact this varied quite a bit over time and geography. In early times when the metal and technology to make swords was rare, such as in Migration Era Europe after the fall of the Roman Empire, only aristocrats could afford them and they were often made with pattern-welded blades or jeweled hilts. As technology and production capacity improved, however, they became much more widely available in a variety of different qualities. In the late middle ages or Renaissance, a finely made and decorated sword for a king might cost more than a commoner's house, but there were also plain mass-produced swords and cheap old ones that a poor person could acquire for a couple of pence. For instance, the short Roman Gladius was issued to every man in the Roman Legion — and there are a lot of men in the Roman Legion. To give a comparison, there is no one price for buying a car in the year 2016, because it depends what kind you're getting. You can buy a new Lamborghini for $200,000 if you're super rich, but there are also $20,000 cars for the less wealthy, and you could get one with a lot of miles and no warranty for $2,000. Compare that with 1907, when there was no mass production of cars and only the obscenely rich could afford a car at all. It is not unrealistic for a poor person to have a sword if it's appropriate for their level of wealth in the context of the setting, but you have to do your research.
Another reason that swords were associated with high status, and thus heroes, was that many societies made owning a sword legal (and sometimes required it), but severely limited where and how you could wear it. Thus, anyone who could walk about armed with a sword in town and not be stopped by the local law was clearly no one to take lightly. After all, they were so high status that they could walk around town with a sword and not be bothered by the local officials! Of course, high status and high character were often conflated; notice how words like noble and high-class imply a high character as well as high status, while vulgar and low-class associate low status and low character. The continued into the armies of the late Renaissance and beyond, where officers were gentlemen of high class and typically carried a sword, while the common grunts were impressed from the lower classes and usually not given one.
Practical ReasonsFor the purposes of medieval and pseudo-medieval fantasy, if rarity is ignored, there's some degree of logic for having swords being iconic of the Warrior and/or Soldier, even if other weapons are much more commonly used: They are (realistically speaking) probably the most convenient close-quarters weapon available until repeating pistols show upnote . Historically, almost nobody used a sword as their primary weaponnote , but just about everybody who had access to swords had some training in swordfighting and carried one as a backup weapon; they also carried swords in places where their primary weapon would be unacceptable (such as when they were far from the battlefield).
And, frankly, swords are comfortable to wear and unencumbering. A sword scabbard is a handy way to carry the weapon and keep your hands free. If you had to walk around with it every day, what would you want to carry? Even in the medieval era, the vast majority of a person's life wasn't spent fighting; it was spent working, visiting friends, in sports, in games, eating, traveling, sleeping, studying, and shopping. It was spent living. If you were high enough status to go about your business armed in the pre-Industrial eras, nothing else combines the convenience of a sword with its effectiveness, especially against unarmored foes — and nobody is wearing all that heavy and expensive armor when they're about their business. Maces, warhammers, and similar weapons are very effective against armor, but decidedly inferior to a sword versus an unarmored foe, nor are they as convenient to walk around with. Axes meant for combat are not the same as tool axes, less comfortable to carry, and less effective against unarmored foes. Polearms and spears are a pain in the posterior to carry about and sure to attract attention. Everyone has a dagger (so they can cut meat, if nothing else), and a sword is a much better weapon. The sword would be the natural choice to wear if you could get away with it.
Swords also required a greater deal of training to use than axes, with various advanced techniques, parrying, and wrist motions, where an axe simply needed to be swung really hard, which marked swords, and the people who used them, as an elite few relative to the "Common" axe-swinging rabble.note
There is a clear parallel with our times. A modern soldier on a battlefield uses a rifle, as it is a superior weapon. A modern person who wants to be armed day-to-day carries a hand gun, as an AK-47 is very inconvenient to carry at all times. A medieval soldier on a battlefield typically uses some variety of polearm. A medieval person who wants to be armed day-to-day carries a sword.