Function arguments (in Python for example)

前端 未结 8 2056
离开以前
离开以前 2020-12-03 16:47

What are [function] arguments? What are they used for?
I started learning Python very recently; I\'m new to programming and I apologize for this basic

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 17:17

    An argument is a special variable that exists only in that function.

    In your example you have a function that takes 2 arguments:

    def add(num1,num2):
        x = num1 + num2
        return x
    

    When I call this function with add(), I have to add in the parentheses what I want num1 and num2 to be. In your case, you have 1 and 3, so you call it like this add(1,3).

    What you're saying there is that you want to call add() and you want the first argument, num1 to be equal to 1, and the second argument, num2, to be equal to 3.

提交回复
热议问题