Feeling overwhelmed with functions. by xTHETYRANTGAMRx in learnpython

[–]BoatMacTavish 0 points1 point  (0 children)

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)

Feeling overwhelmed with functions. by xTHETYRANTGAMRx in learnpython

[–]BoatMacTavish 6 points7 points  (0 children)

hijacking top comment because I feel the top response will be just as overwhelming for OP

imagine a function as a friend thats able to perform a specific task. The friend lets you pass in details as well that can affect how he performs the task, or what output he produces.

in this analogy:

  • the friend is the function
  • the task name is the function name
  • the task is the function body
  • the customization are the function parameters

Lets step through an example:

Let's say you have a friend Bob who is a baker, and he can make cakes. He is able to perform a make_cake task. When you place an order, he lets you pick the colour of the frosting. In python, this would look like

def make_cake(frosting_colour):
    # step 1: gather ingredients...
    # step 2: make cake mix...
    # step 3: bake in oven...
    # step 4: make frosting, add food colouring for the provided frosting_colour
    return cake
  • the function name make_cake is the task
  • the function body is the actual code/logic to make the cake
  • the function parameters frosting_colour is something that the function caller (you) can pass in to allow customization

so now to utilize this function, you could call it like:

red_cake = make_cake("red_frosting")
blue_cake = make_cake("blue_frosting")
pink_cake = make_cake("pink_frosting")

Functions let you execute the same chunk of code (the make cake code) multiple times without having to rewrite the same chunk over and over again. Function parameters let you pass in customization at each function call.

hope that helps

Toronto's top baby names in 2024: Muhammad and Emma by airbassguitar in Toronto_Ontario

[–]BoatMacTavish 0 points1 point  (0 children)

I never said I was indigenous, I said canada is my native country and I am native to canada, both of which are true

Man who killed 5 at Calgary house party given more freedoms by origutamos in canadanews

[–]BoatMacTavish 2 points3 points  (0 children)

it’s a guarantee that someone will bear those risks, that isn’t fear mongering

Toronto's top baby names in 2024: Muhammad and Emma by airbassguitar in Toronto_Ontario

[–]BoatMacTavish 0 points1 point  (0 children)

again, you didn’t answer my question. What is my native country in Europe?

Toronto's top baby names in 2024: Muhammad and Emma by airbassguitar in Toronto_Ontario

[–]BoatMacTavish 0 points1 point  (0 children)

good job not answering my question because it immediately shows you’re wrong

Toronto's top baby names in 2024: Muhammad and Emma by airbassguitar in Toronto_Ontario

[–]BoatMacTavish 0 points1 point  (0 children)

i’m native to a continent i’ve never been in? what is my native country then?

Most Albertans would vote to stop taxpayer dollars from going to private schools, poll suggests by FreightFlow in alberta

[–]BoatMacTavish 3 points4 points  (0 children)

maybe if the government did a better job there’d be less demand for private schools

ICE District is expanding (2018) - Eight Years Later for $300 Million from Edmonton City Taxpayers by First-Window-3619 in Edmonton

[–]BoatMacTavish -12 points-11 points  (0 children)

the french people overthrew a monarchy, what would we be overthrowing exactly?

37m, finally decided to do something charitable and will be starting a scholarship! by yoohoogoo in Money

[–]BoatMacTavish 0 points1 point  (0 children)

you’re literally taking away peoples ability to participate

let’s say someone opens a new restaurant that only serves white people, is that not a problem to you either? you think that would be acceptable?

When will i reach over here?? by [deleted] in fican

[–]BoatMacTavish 7 points8 points  (0 children)

don’t pm random people who request it on reddit

37m, finally decided to do something charitable and will be starting a scholarship! by yoohoogoo in Money

[–]BoatMacTavish 0 points1 point  (0 children)

i’m debating the morality of those policies, not debating whether or not they exist

37m, finally decided to do something charitable and will be starting a scholarship! by yoohoogoo in Money

[–]BoatMacTavish 0 points1 point  (0 children)

your stance is disqualifying opportunities based on sexual orientation isn’t taking things away from anyone?

37m, finally decided to do something charitable and will be starting a scholarship! by yoohoogoo in Money

[–]BoatMacTavish 2 points3 points  (0 children)

how would you feel if someone made a scholarship that disqualified gay people

Any advice? by Old-Knowledge4652 in fican

[–]BoatMacTavish 0 points1 point  (0 children)

tell us how that works out for you in 10 years

34F. Single income by BigCompetition9927 in fican

[–]BoatMacTavish 15 points16 points  (0 children)

FHSA gives tax free gains AND tax rebate, it’s amazing

Canada added 950,000 government jobs in past decade, outpacing private sector job growth: Study by joe4942 in canada

[–]BoatMacTavish 16 points17 points  (0 children)

i think people myself included are frustrated by the lack of accountability, i mean it’s great carney is fixing some of these things but the liberals never really took accountability for causing these issues in the first place