day4变量

master
dugulingping 2022-11-05 00:34:06 +08:00
parent 56e96faa15
commit 4d52cee4a0
3 changed files with 34 additions and 10 deletions

8
.idea/.gitignore vendored
View File

@ -1,8 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -32,7 +32,6 @@ func lissajous(out io.Writer) {
nframes = 64
delay = 8
)
freq := rand.Float64() * 3.0
anim := gif.GIF{LoopCount: nframes}
phase := 0.0
@ -53,5 +52,4 @@ func lissajous(out io.Writer) {
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim)
}

34
day4/var.go Normal file
View File

@ -0,0 +1,34 @@
package main
import "fmt"
func main() {
// var 变量名字 类型 = 表达式
var hello string = "world"
fmt.Println(hello)
// 其中“类型”或“= 表达式”两个部分可以省略其中的一个。
// 如果省略的是类型信息,那么将根据初始化表达式来推导变量的类型信息。
// 如果初始化表达式被省略,那么将用零值初始化该变量。
// Go语言中不存在为初始化的变量
//可以在同一句声明语句中声明不同类型的变量
var b, f, s, i = true, 3.1415926, "four", 5 // bool float string int
fmt.Println(b, f, s, i)
// 可以使用简短变量声明
// 名字 := 表达式
operation := 1 + 10 - 5 // 5
fmt.Println(operation)
// 可以十分简单的交换两个变量的值
var number1, number2 int = 2, 6 // 2, 6
fmt.Println("before:", number1, number2) // 2, 6
// swap。。。
number1, number2 = number2, number1 // 交换
fmt.Println("after:", number1, number2) // 6, 2
// 指针
}