Parentheses in Profitable App project


Just hoping someone could clarify the use of parentheses in the cleaning process. The worked solution has:
if (reviews_max[name] == n_reviews) and (name not in already_added):

however, I get the same result when I remove the parentheses:

if reviewsmax[name] == n_reviews and name not in alreadyadded:

Thank you



Hello @jbringinsnz. Could you please post a link to the screen on which you are working? Helps us to know the entire problem statement.

1 Like

Hi @jbringinsnz ,

Are you asking whether the parentheses ( ) are optional in the if statement:
if **(**reviews_max[name] == n_reviews**)** and **(**name not in already_added**)** :

If so, you are right, the parentheses ( ) are optional if the order of operation or code is easily understood.

I read this article which may answer your question. The below example is from this article.

Click on the triangle bullet below to view Example from this article:


The below code is from this article

When we code complex conditions, it’s a good idea to use parentheses ( ). Sometimes they’re required to change Python’s order of operations. And at other times they simply make code easier to understand.

Let’s see how combining conditions with `and` and `or` looks. Here’s a quick example:

condition = (A and B) or C

This combined condition tests `True` in one of two scenarios:

When the combination of A and B is True.
Or when C is True.
When both the first and second condition are False, then this combination is False too.

Here’s another example:

condition = (A or B) and C
This combination is True when two things happen at the same time:

Either A or B is True.
And C tests True.

Thank you for your time.