首页 > 其他分享 >0076-Go-常量

0076-Go-常量

时间:2022-10-30 08:23:41浏览次数:87  
标签:const 常量 fmt Println 0076 Go main

环境

  • Time 2022-08-23
  • Go 1.19

前言

说明

参考:https://gobyexample.com/constants

目标

使用 Go 语言的常量。

示例

package main

import (
    "fmt"
    "math"
)

const s string = "constant"

func main() {
    fmt.Println(s)

    const n = 500000000

    const d = 3e20 / n
    fmt.Println(d)

    fmt.Println(int64(d))
    // 数值型常量的类型可以自动转换
    fmt.Println(math.Sin(n))
}

总结

使用 Go 语言的常量。

附录

标签:const,常量,fmt,Println,0076,Go,main
From: https://www.cnblogs.com/jiangbo4444/p/16840441.html

相关文章

  • 0077-Go-for 循环
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/for目标使用Go语言的for循环。单条件循环类似其它语言中的while循环。packagemain......
  • 0078-Go-if else 条件判断
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/if-else目标使用Go语言的if/else条件判断。条件判断条件判断的小括号可以省略,但是后面的......
  • 0079-Go-switch 分支
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/switch目标使用Go语言的switch分支语句。整数分支packagemainimport"fmt"funcmai......
  • 0080-Go-数组
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/arrays目标使用Go语言的数组。申明数组packagemainimport"fmt"funcmain(){v......
  • 0081-Go-切片 slice
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/slices目标使用Go语言的切片类型。新建切片类型packagemainimport"fmt"funcmain()......
  • 0082-Go-关联类型 map
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/maps目标使用Go语言的关联类型map。新建mappackagemainimport"fmt"funcmain(){......
  • 0073-Go-hello world
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/hello-world目标使用Go语言打印helloworld。初始化项目gomodinitjiangbo/go打印hel......
  • 0074-Go-值类型
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/values目标使用Go语言的字符串,整型,浮点型和布尔类型。示例packagemainimport"fmt"fu......
  • Golang 基于 flag 库实现一个命令行工具
     Golang标准库中的flag库提供了解析命令行选项的能力,我们可以基于此来开发命令行工具。 假设我们想做一个命令行工具,我们通过参数提供【城市】,它自动能够返回当前......
  • golang中的锁竞争问题
    当我们打印错误的时候使用锁可能会带来意想不到的结果。我们看下面的例子:packagemainimport("fmt""sync")typeCoursewarestruct{mutexsync.RWMutexIdint6......