例如:
((360/2)*x)/2 # output : 90.0*x
# I want the output to be : 90*x
int(((360/2)*x)/2) # TypeError
是否有函数可以将90.0x转换为90x
您可以使用xreplace
来遍历表达式并进行更改:
>>> eq
2.0*x
>>> eq.xreplace({i: int(i) for i in eq.atoms(Float) if i == int(i)})
2*x
感谢@OscarBenjamin
nsimplify(((360/2)*x)/2) # output : 90*n