Why this isn't a valid reassignment


I have a similar problem. Here is my code:

x = ["fizz","notfizz","alsonotfizz"]
def fizz_count(x):
count = 0
for items in fizz_count:
if items == "fizz":
return count = count + 1
return count

The error I get is:

File "python", line 6
return count = count + 1
SyntaxError: invalid syntax

Can't understand why this isn't a valid reassignment. Any help is much appreciated.

Lists + Functions

Did you mean,

for item in x:



I'm still getting the same error code though:

File "python", line 7
return count = count + 1
SyntaxError: invalid syntax


This is JavaScript syntax, not Python. Remove the curly braces. You also should not be returning inside the loop. Let the loop play out, then return the final result.


I should rightly have just said, this is not Python syntax, since so many other languages use it, not just JS.


Thank you! Problem solved.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.