Lists + Functions


#1

# Write your function below!
def fizz_count[x]:
    count = 0
    for item in x:
        if item == "fizz":
            count = count + 1
    return count

x = ["fizz","cat","fizz"] 
small = fizz_count(x)
print small

I can't figure out what's going on with it,please help me !
It says

Your code appears to raise an error, see the console window for the error message!


#2

Should be parentheses, not box brrackets.

def fizz_buzz(x):

Out of interest, what is the error message in the console (the complete message)?


#3

the message is this:
File "python", line 2
def fizz_count[x]:
^
SyntaxError: invalid syntax

I didn't understand what it meant at that time.Although I solved this problem now,i don't know why i should write parentheses,not box brrackets when it wants me to take a list as input in writing a function.(sorry,English isn't my mother tongue,if you feel anything hard to understand,please ask me to explain my question again.)


#4

An easy way to distinguish between parameter and index is to look at the objective. To pass data to a function, we use a tuple, which is a parameter or argument. To access an element of a list, or a member value of a dictionary we use an index/key. Indices are always box brackets. Tuples are always parentheses, unless we're accessing the data contained. Then we treat it like we would a list, with subscript syntax.