How to return a value from a function?

前端 未结 5 1026
Happy的楠姐
Happy的楠姐 2021-01-28 21:39

Yes, I\'ve read tons of examples on this but I still don\'t get it.

I\'m learning Python and I made this script in order to help me understand how to \'return\':

5条回答
  •  感情败类
    2021-01-28 22:03

    Try this:

    payrise = payrise + random_number()
    

    When you call a function that returns a value (a random number in this case), you're supposed to do something with the returned value.

    Also notice that the variable random that was defined locally inside random_number() can not be "seen" from other functions - unless you declare a new variable locally, but it can have any name you want. Another way to say the same would be:

    random = random_number()   # can be any name, I'm using `random` again
    payrise = payrise + random
    

提交回复
热议问题