Use .free_symbols to identify variables in an expression.