If you buy a house to rent out, you are buying it with post-tax dollars and you are paying tax on the rental income it generates. Being a landlord can be more work and less profitable than some people anticipate. That said, for the next 8 years under the new tax law landlords will get to deduct 20% of their rental income making the overall tax picture pretty agreeable.
A 401k is tax-advantaged as it is funded with pre-tax dollars, you'll pay income tax on distributions but you're saving at your marginal rate on the front-end and paying your future effective rate on the back-end. If there is no match, people typically prioritize IRA contributions over 401k, but the limit on IRA contributions is so low that you'd also want to put some toward the 401k. Your 401k/IRA are relatively hands off investing, and there are penalties for withdrawing early. With an employer match it's a very easy decision, without a match it's still a good idea.
Personally, I like both, I am a landlord and I contribute to my 401k. I only contributed up to my employer's match amount for a few years while I focused on paying off debts and buying property, now I've shifted to contributing more to the 401k. Investment strategy should change over time. I think of it as a way to diversify.
Just be comfortable with the risks and potential time/money commitments associated with real estate investing. The risks associated with either are hard to peg, so picking one over the other is not easy. If you like the idea of being hands-on and actively managing a rental, it might be the better option. If, however, you think you'd ultimately just pay others to do everything associated with the rental then it might be much less lucrative than dumping money in your tax-advantaged retirement accounts (even if you do it all yourself it could be much less lucrative than your retirement accounts).