Why this isn't a valid reassignment


#1

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
#2

Did you mean,

for item in x:

?


#3

I'm still getting the same error code though:

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


#4

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.

Edit

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


#5

Thank you! Problem solved.


#6

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