If a zombie is close enough for you to kill it with a sword it it too damn close. It's more likely to kill you than you to cut off its head.
And you probably aren't good enough with a gun to make an accurate "head shot" with a pistol at a moving target.
You are better off fleeing than fighting.
You could, of course, get yourself trained properly in small-arms combat prior to a civilization-ending event, and I'm not saying that it wouldn't be loads of fun, but most people, especially people who read online guides like this, don't show a lot of forethought about doing things BEFORE an event.
And here's a simple fact: if you don't know what you're doing with a firearm you are much more likely to injure or kill yourself or someone around you than you are to use it effectively against a bad guy or zombie. Guns are lethal things. Stay clear of them until you can be properly trained.
Knives are a different thing. You'll need knives to help you DO things, not necessarily to KILL things. Remember, killing things is hard and killing something with a knife is close-up, messy work. It's a very bad idea to get that close to a zombie. I recommend getting yourself a versatile knife that you can use cut things with. Things like rope, wood, and food, not reanimated corpses.
And you will also need a way to sharpen your knife. Knives become dull quickly, especially if you use them. And knife sharpening is a difficult skill to master. So either plan on scrounging up fresh knives frequently or figure out how to sharpen the one that you have.