课程: Computer Science Principles: Programming
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Return values from functions
- Functions, sometimes called methods, are tools for programmers to take common actions and to group them to call using the function name. With a function, you can send in values for it to use and perform actions on it. But you often need to get information out of it. Because of variable's scope, any variable that you create inside of it, will be thrown away when the function is finished. So you need to have a way to return a value from the function when it is called. There are three ways to work with a value. The first is to use a literal. A literal is the value itself, without any name or container. It is simply the value. So I could assign a variable with a literal value, like five. The second is to use a variable. That variable has a value, and I can assign that to another variable. The third is with a function or method. You essentially use it like a variable, or literal. But to do this, you need to have it return a value. Like a variable, it will have a type. In this case, the…