Why the double parenthesis

I was working on step 7 of the Python Lists: Medical Insurance Estimation Project.

Here are the instructions:

We want to add our estimated insurance data for Maria, Rohan, and Valentina to the estimated_insurance_data list.

Use .append() to add ("Maria", maria_insurance_cost) to estimated_insurance_data. Do the same for Rohan and Valentina.

here’s is the code I entered:

  estimate_insurance_data.append("Maria", maria_insurance_cost)

it gave me the following error:

Traceback (most recent call last):
File “script.py”, line 24, in
estimate_insurance_data.append(“Maria”, maria_insurance_cost)
TypeError: append() takes exactly one argument (2 given)

eventually I looked at the hint and basically showed a double parenthesis (see code below from the hint)

estimated_insurance_data.append(("Maria", maria_insurance_cost))
estimated_insurance_data.append(("Rohan", rohan_insurance_cost))
estimated_insurance_data.append(("Valentina", valentina_insurance_cost))`

I was able to get to work with the double parenthesis. But I don’t understand why it worked. Can anyone explain why the double parenthesis worked and what other situations I will need to use double parenthesis? I’m a very rule driven person and I have a hard time understanding concepts with rules.

Evidently list.append() only takes one argument. What the second parentheses do is append a tuple. Perfectly fine, if that is what you want to do. Is the list one of tuples to begin with?

Your finished list will look something like this:

>>> print (estimated_insurance_data) 
[("Maria", 575), ("Rohan", 495), ("Valentina", 425)]
>>>

I made up the numbers.

It makes sense now. Thanks so much for explaining it to me. :grinning:

1 Like