加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Go by Example: Constants

发布时间:2020-12-16 19:27:36 所属栏目:大数据 来源:网络整理
导读:Go by Example: Constants Go语言支持字符常量、字符串常量、布尔常量和数值常量。 import"fmt"import"math"constsstring="constant"//const申明一个常量值funcmain(){fmt.Println(s)constn=500000000//const语句可以出现在任何var语句出现的地方constd=3e20

Go by Example: Constants


Go语言支持字符常量、字符串常量、布尔常量和数值常量。

import"fmt"
import"math"
constsstring="constant"//const申明一个常量值
funcmain(){
fmt.Println(s)
constn=500000000//const语句可以出现在任何var语句出现的地方

constd=3e20/n//常量表达式可以表示任意精度
fmt.Println(d)
fmt.Println(int64(d))//数字常量在赋予类型之前是没有类型的,比如强制类型转换
fmt.Println(math.Sin(n))//在使用的上下文中一个数字可以被给予一个类型,
//比如:一次变量复制或者函数调用,这里的math.sin期望一个//float64.
}

执行代码:

$gorunconstant.go
constant
6e+11
600000000000
-0.28470407323754404


原文地址:https://gobyexample.com/constants

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读