The string trick would do the job, but maybe the tree method would be nicer. How can I walk in the tree ? Is the tree the one of simply or another one ?
*Christophe BAL* *Enseignant de mathématiques en Lycée **et développeur Python amateur* *---* *French math teacher in a "Lycée" **and **Python **amateur developer* 2015-03-09 15:44 GMT+01:00 slelievre <samuel.lelie...@gmail.com>: > slelievre: > > projetmbc: >> >> suppose that I have *sqrt(6)*(sqrt(3)+5)*. How can I count >>> >> the number of square root in this expression ? >>> >> >> sage: a = sqrt(6)*(sqrt(3)+5) >> sage: a >> sqrt(6)*(sqrt(3) + 5) >> sage: s = str(a) >> sage: s >> 'sqrt(6)*(sqrt(3) + 5)' >> sage: s.count('sqrt') >> 2 >> > > or you could explore the expression's tree > with a.operator(), a.operands(), etc., and > count the number of 'sqrt' operators. > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.