Python | sympy.count() method
Last Updated :
01 Feb, 2023
Using the count() method in the sympy module, we can count the number of variables used in the mathematical function. count() method returns the number of variables used in the mathematical function.
Syntax : sympy.count(x)
Return : the count of variables.
Code #1: With the help of the below examples, we can clearly understand that using sympy.count() method we can count the number of variables in a given expression.
Python3
from sympy import *
x, y, z = symbols( 'x y z' )
geek = sqrt((x + 1 ) * * 2 + x).count(x)
print (geek)
|
Output:
2
Code #2:
Python3
from sympy import *
a, b = symbols( 'a b' )
geek = (log(a) + log(b) + log(a) * log( 1 / b)).count(log)
print (geek)
|
Output:
4
Code #3:
Python3
from sympy import *
a, b = symbols( 'a b' )
geek = (log(a * b * * ( 1 - log(a)))).count(b)
print (geek)
|
Output:
1
Share your thoughts in the comments
Please Login to comment...