今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Functions
- [Instructor] Let's look at function declarations and usage in Go, including multi-value returns, named returns and naked returns. Let's start with declarations. We declare functions using the func keyword. Let's start simple and create a greet function that returns a string and we'll invoke it in our main function. Let's run the program. All right, so far so good. We'll comment this out. Since Go doesn't support overloading, let's add a variant of the previous function that accepts a name string and incorporates it in the result. Let's go down to main and invoke the function. Let's clear, run again, and here we are. We'll comment this out. Let's add another one still, this time using a named return style. All right, let's talk about what's happening here. In this version, we've pre-declared greeting in the return portion of the function signature itself. This is called a named return parameter. Inside…