Function arguments (in Python for example)

前端 未结 8 2025
离开以前
离开以前 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:25

    The stuff in the parentheses are called arguments. Basically these are variables that you want the function to work with. For example, say you have a function, and you want it to print a word when you call it. With arguments, you can define what that word will be. Here is an example:

    def hi(word):
        print word
    

    now, if I do something like this:

    hi('Hello!')
    

    it will print:

    'Hello!'
    

    hi() gets passed 'Hello!' as a variable called word, and then it prints that word.

提交回复
热议问题