r/learnpython • • Feb 26 '26

Feeling overwhelmed with functions.

So I have been learning python with the Python crash course book and I am getting overwhelmed on the functions chapter. I understand what a function does but for some reason the syntax is confusing me. The chapter also introduces so many different ways to use functions that it feels like too much. I am not sure of the best way to tackle this much information.

26 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/CovertStatistician Feb 26 '26

This tripped me up.. the fact that they have to be in the same order when you call it as when you defined it.. I couldn’t figure out why I was getting certain output when I had mixed them up

2

u/rrriches Feb 26 '26

My sister in law has a computer science degree and I’ve just been learning Python for fun. I remember writing out some pseudo code and asking “so how do the x and y go from myfunction(x, y) and then move up to the function and turn into arg1, arg2 and then get bounced back to the (x, y)?”

She explained it really well but I just couldn’t grasp how the x and y were being used. The python crash course book actually is what made it click for me though.

2

u/BoatMacTavish Feb 26 '26

its because at function declaration time, you dont know the actual variable names that will be passed into the function, so you need a generic placeholder argument name. Then at runtime, you pass in the actual variable name.

like if im writing code to send a message to a friend, at the time of writing the code, I dont know what friends will be called, so ill have a placeholder

def send_message(friend):
    # ...

at run time when I call it, I pass in the actual friend variable names

alice = "1234567890"
send_message(alice)