from sympy import*
def z(l):
print(l.subs(x,1))
def f():
x = symbols('x')
l = x*x
z(l)
f()
运行后,在f()调用z()时x未定义。但是改为如下就能成功:
from sympy import*
def z(l):
print(l.subs(x,1))
if __name__=='__main__':
x = symbols('x')
l = x*x
z(l)
请问对于第一个代码如何修改,能通过调用f()函数得到结果