Liouville type results for periodic and almost periodic linear operators