Function arguments (in Python for example)

前端 未结 8 2027
离开以前
离开以前 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.

    0 讨论(0)
  • 2020-12-03 17:26

    Functions would be useless if you can't give them information they should handle.
    Arguments are such information.

    def GiveMeANumberAndIDuplicateIt(x):
        return x * 2
    
    def DontGiveMeAnythingAtAll():
        return None
    
    0 讨论(0)
提交回复
热议问题