I am trying to find the order of a polynomial. I have created a method called "order" to set self.order to the order of the polynomial it is used on, ie polynomial1.order (p1.order). However, in order to add the order attribute so p1.order can work, I find I need to do p1.order() first. How can I remove this step to make it automatic?
Here is my code, do inform me if there are any other faux pas, I'm new to classes:
class Polynomial(object):
def __init__(self,*p_coeffs):
self.p_coeffs = list(p_coeffs)
def order(self):
self.order = len(self.p_coeffs)
p1 = Polynomial(2,0,4,-1,0,6)
p2 = Polynomial(-1,3,0,4.5)
p1.order() #<-- this step is the one I want to remove so I do not need to write it for every polynomial
print(p1.order)
Thanks in advance
EDIT: I need to keep my "order" method in the process