I am going to learn how to play guitar but first i have to buy one. I am a complete layman in this topic so I would like to know something about it.
First, don't worry about buying used or buying inexpensive instruments. Some great guitarists have had second-hand or factory-second guitars and parts for their main instruments.
Also, don't be afraid of getting inexpensive instruments. The price difference between, for example, a $1000+ Custom Shop Fender Stratocaster and an Asian-made Squier Strat is more due to country of origin than any other factor.
You want a properly set-up neck. It should have some curve to it, called "relief", which allows the strings fretted closer to the headstock to vibrate freely away from higher frets. If you look down the neck, the frets should be even, with none of the frets being noticeably higher than the others. Play each string at each fret, and if any note doesn't ring out, there are neck or fret issues that will get in the way of your progress. Put that one down and pick up another one.
Also, be wary of sharp fret ends sticking out from the neck. This is a sign that the wood in the neck is dry and shrinking, or of poor-quality fret work. Either way, those sharp ends will be uncomfortable to your hands, and fixing it will take time and/or money. Pick another one.
Try the tuners. They should turn smoothly.
If the guitar is electric or electric-acoustic, plug in and try all the positions on the switches and the knobs. The potentiometers, the part the knobs connect to, should not be scratchy. The guitar should not cut out when the cable is shaken, nor if the pickup switches are wiggled.
Guitars that look messed up can still play well. Ask Willie Nelson or Eddie Van Halen. Minor or even fairly significant wear will not affect playability, and in fact, many manufacturers make brand-new instruments that intentionally look like they've been well-played for several years.
If you're looking to play acoustic guitar, there's a controversy. Many instruments are made of laminate, which is thin sheets of wood glued together, a bit like a fancy plywood. A solid-wood guitar will tend to sound better the longer you own it and the more you play it, but solid-wood guitars will also tend to change depending on humidity. You can cause damage to such guitars simply by leaving it out of it's case over the winter when the heater dries out the air. Laminate guitars are much more survivable in such conditions. My suggestion is that you get a reasonable-quality laminate guitar at roughly the $200 price point, from reliable brands such as Fender or Takemine, and if you keep at it and start finding that your guitar is holding back your progress, then start looking for a nicer solid-wood instrument.