一、Demo 之常用变量类型以及函数
package main
import (
"fmt"
"time"
)
var testNumber = 20
func main() {
//var _age int = 123
var _age = 24
datetime := time.Now()
fmt.Println("Hello, Go! I'm ",_age,"year's old","当前时间",datetime)
fmt.Println("当前时间",datetime)
max(12,11)
}
func max(num1,num2 int) {
var result = num1 + num2 + testNumber
//getString :=[...]string{}
var getString[12] string
for i := 0 ; i < 10 ; i++{
result += i
fmt.Println(i,"测试一下循环输出")
getString[i] = fmt.Sprintln(i,"测试一下字符串数组的赋值")
}
fmt.Println(result,"这个是字符串数组:",getString)
fmt.Println(fmt.Sprintln(ReturnResultAndGetString(20,21)),"测试一下函数的返回值")
fmt.Println("测试一下函数的返回值",fmt.Sprintln(ReturnResultAndGetString(20,21)),"")
fmt.Println("测试返回值不同的使用方式",fmt.Sprintln(ReturnResult(20,21)),"")
}
func ReturnResultAndGetString(num1,num2 int) (result int,getString[12] string){
result = num1 + num2 + testNumber
//getString :=[...]string{}
for i := 0 ; i < 10 ; i++{
result += i
fmt.Println(i,"测试一下循环输出")
getString[i] = fmt.Sprintln(i,"测试一下字符串数组的赋值")
}
fmt.Println(result,"这个是字符串数组:",getString)
return
}
func ReturnResult(num1, num2 int) (int, [12]string) {
var result = num1 + num2 + testNumber
//getString :=[...]string{}
var getString[12] string
for i := 0 ; i < 10 ; i++{
result += i
fmt.Println(i,"测试一下循环输出")
getString[i] = fmt.Sprintln(i,"测试一下字符串数组的赋值")
}
fmt.Println(result,"这个是字符串数组:",getString)
return result,getString
}