// week1 project main.go//导入一个包(目录) package main //导入方法 import "fmt" //createMessage函数(参数,类型)返回值的类型(这里是string),这里可以返回多个类型func create(name string)(string, int){........} func createMessage (name string) string { //如果name长度小于0 if len(name) == 0 { return "Hello world" } else { return "Hello " + name } } func main() { //打印结果 fmt.Println(createMessage("zhangs")) fmt.Println(createMessage("lisi")) fmt.Println(createMessage("")) }
时间: 2024-11-01 04:54:49