SymPy | Python中的 Prufer.nodes()
Prufer.nodes() :nodes()是一个 sympy Python库函数,它返回树中的节点数。
Syntax :
sympy.combinatorics.Prufer.prufer.nodes()
Return :
the number of nodes in the tree
代码 #1:nodes() 示例
# Python code explaining
# SymPy.Prufer.nodes()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
# Using from
# sympy.combinatorics.prufer.Prufer.nodes()
# Creating Prufer
a = Prufer([1, 2, 3], [2, 4, 5])
# nodes value
print ("Prufer a nodes : ", a.nodes)
输出 :
Prufer a nodes : 5
代码 #2:nodes() 示例
# Python code explaining
# SymPy.Prufer.nodes()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
# Using from
# sympy.combinatorics.prufer.Prufer.nodes()
# Creating Prufer
b = Prufer([1, 2, 3, 2, 4, 5], [6, 7], [8])
# nodes value
print ("Prufer b nodes : ", b.nodes)
输出 :
Prufer b nodes : 8