提交 5993491e 编写于 作者: _Fighter's avatar _Fighter

add

上级 a402133a
package main
import "fmt"
import (
"fmt"
"math"
"math/cmplx"
)
/*此处不能使用 := 来定义变量
go 语言都中包内变量,go 没有全局变量
......@@ -42,7 +46,56 @@ func variableShorter() {
x ,b ,c,e,f := 3.23,4,"abdad",true, 4.54
fmt.Println(x,b,f+1, c,e)
}
func euler() {
c:=3 +4i
fmt.Println(cmplx.Abs(c))
}
/*强制转换*/
func triangle() {
a ,b :=3,5
var c int
c = int(math.Sqrt(float64(a*a + b*b)))
fmt.Println(c)
}
/*常量*/
func consts() {
/*const filename="abc.txt"
const a, b = 3, 4 */
/* 集中写常量*/
const(
filename ="abc.txt"
a, b = 3, 4
)
var c int
c = int(math.Sqrt(a*a + b*b))
fmt.Println(filename,c )
}
/*枚举*/
func enums() {
/*常量定义必须给赋值*/
const(
cpp=iota // 自动填充递长
java
python
golang
javasscipt
_ // 下划线跳过自动填充值
php
)
const x int =0
fmt.Println(x, cpp,python,golang,javasscipt,java,php)
/*设置自增表达式*/
const(
b = 1 <<(10*iota)
kb
mb
gb
tb
pb
)
fmt.Println(b,kb,mb,gb,tb,pb)
}
func main() {
variableZeroValue()
......@@ -50,5 +103,8 @@ func main() {
variableTypeDeduction()
variableShorter()
fmt.Println(x1,x2,x3)
euler()
triangle()
consts()
enums()
}
module "learngo"
\ No newline at end of file
module learngo
go 1.15
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册