ARTICLE AD BOX
In Python, variable assignment strictly evaluates from right to left. The variable you are defining must always be on the left side of the = operator, and the calculation or value must be on the right.
So, you are getting a SyntaxError: cannot assign to operator in your final block of code.
Incorrect: Python thinks you are trying to change the value of the math
value ** 2 = square operatorCorrect:
square = value ** 2You actually nailed it perfectly in your first example! However, if your goal is to write this as concisely and efficiently as possible, stick with the list comprehension from your third example. It is the most "Pythonic" way to generate a list like this:
squares = [value**2 for value in range(1, 11)]@Tommy_1978 For more details on how this works under the hood, you can check out this official Python documentation on assignment statements or read up on Python Data Structures (List Comprehensions).
