Python| sympy.as_two_terms() 方法
借助sympy.as_two_terms()
方法,我们可以通过数学表达式中的常数值来分隔数学表达式,并使用sympy.as_two_terms()
方法返回一个元组。
Syntax : sympy.as_two_terms()
Return : Return the tuple of elements separated by constant value.
示例 #1:
在这个例子中,我们可以看到通过使用sympy.as_two_terms()
方法,我们能够得到由常量值分隔的元素元组。
# import sympy
from sympy import *
x, y = symbols('x y')
# Using sympy.as_two_terms() method
gfg = (3 * x + 5 * y + 6).as_two_terms()
print(gfg)
输出 :
(6, 3*x + 5*y)
示例 #2:
# import sympy
from sympy import *
x, y = symbols('x y')
# Using sympy.as_two_terms() method
gfg = (x**2 + 4).as_two_terms()
print(gfg)
输出 :
(4, x**2)