How to retrieve values after using an expression to define a subdomain?

In 4.3.1 of the fenics tutorial, the tutorial describes creating a class K, in order to have a variable coefficient kappa for solving problems. It shows how to create the class K, and how to assign kappa values, but it doesn’t show how to actually use those values in an Expression.

Class K(Expression):
    def set_k_values(self, k_0, k_1):
        self.k_0, self.k_1 = k_0, k_1
    def eval(self, value, x):
        tol = 1e-14
        if x[1] <= 0.5 + tol:
            value[0] = self.k_0
        else:
            value[0] = self.k_1

kappa = K(degree=0)
kappa.set_k_values(1, 0.01)

From here, how do I use kappa in an expression?

So it turns out that kappa can be used immediately in a variational problem, a la:

F = kappa*dot(grad(u), grad(v))*dx
solve(F == 0, u, bcs)