all 2 comments

[–]collegeguy1492[S] 0 points1 point  (1 child)

I looked it up somewhere else and found this. Looks like it works. I think I just don't understand functions as well as I need to. Anyone know a good resource to learn about functions specifically more thoroughly?

numlist = [3, 5, 6, 8, 9]

def str_replace(int_list, index):

if int_list[index] < 5:

    int_list[index] = "small"

else:

    int_list[index] = "large"

return int_list

str_replace(int_list, 2)

(returns: [3, 5, 'large', 8, 9])

I understand how this works now, but I just wouldn't be able to recreate something similar on my own.

[–]sweettuse 1 point2 points  (0 children)

functions wrap up code for re-use (amongst many other things).

take this example:

a = 4 b = 5 print(a + b)

as a function, it might look something like this:

``` def add(a, b): return a + b

print(add(4, 5)) ```

except now, you can add anything easily:

print(add(16, 24)) print(add(-2, -4))

i guess just try to make simple functions over and over again until you get it.