Just looking for some clarification regarding “Reggie’s Linear Regression” Off-Platform Project found here:
Under the calculate_error function, I don’t understand the syntax:
def calculate_error(m, b, point): x_point, y_point = point
- When I printed the type, I realised it was a tuple, but why is it not enclosed in parentheses ()?
- I also thought assignment is usually performed left to right so does this line assign both x_point and y_point to the tuple point?
In an attempt to understand it better, I inverted the line i.e.
def calculate_error(m, b, point): point = x_point, y_point
but then the following testing of the function no longer worked correctly.
To get around this I rewrote it as follows:
def calculate_error(m, b, point): x_point = point y_point = point
but I do not view this as good practice, more of a hack per say.
In short, could someone please clarify the differences:
- why/how is it a tuple if not enclosed in ()?
- why does the line not work if inverted and what is the difference?
Please excuse my formatting, first post. I’ll get the hang of it!