When you write f(x) = cos(x), you define a symbolic expression. If you want to define a Python function, just do
sage:  f = lambda x: 1