I'm pretty new to python, and I wonder how I can print objects of my class fracture. The str funcion is set properly, I guess
def __str__(self):
if self._denominator == 1:
return str(self._numerator)
else:
return str(self._numerator)+'/'+str(self._denominator)
because of
>>>print ('%s + %s = %s' % (f1,f2,f1+f2))
1/3 + -1/4 = 1/12
Now I'd like to print it properly as a sorted array, and I hoped to get something like
>>>print(', '.join(("Sam", "Peter", "James", "Julian", "Ann")))
Sam, Peter, James, Julian, Ann
But this didn't work for my fracture or even for numbers (like print(' < '.join((1,2,3)))
)
All I got was:
for i in range(len(fractures)):
if i+1 == len(fractures):
print (fractures[i])
else:
print (fractures[i], end=' < ')
Is this really the best solution? That's quite messing up the code, compared on how easy this works with strings...