Disclaimer: There are many questions asked on Stack Overflow regarding the error message
SyntaxError: cannot assign to function callin Python. This question provides resources on this error and also may help reviewers find the correct duplicates. This question should not, itself, be used as the target.
The error message
SyntaxError: cannot assign to function call
is produced by all of the following examples:
foo() = 3
mydict = {}
mydict('key') = 3
for i() in [1, 2, 3]: pass
[x for int(x) in '123']
with open('file.txt') as my_file(): pass
Why is this syntax not valid, and what code should I write instead?