首页 > 其他分享 >0075-Go-变量

0075-Go-变量

时间:2022-10-30 08:23:49浏览次数:69  
标签:变量 fmt var Println 0075 申明 Go

环境

  • Time 2022-08-23
  • Go 1.19

前言

说明

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

目标

使用 Go 语言变量的申明和使用变量。

示例

package main

import "fmt"

func main() {

    // 类型推断
    var a = "initial"
    fmt.Println(a)

    // 申明变量和类型,一次申明多个
    var b, c int = 1, 2
    fmt.Println(b, c)

    var d = true
    fmt.Println(d)

    // 默认值
    var e int
    fmt.Println(e)

    // 申明并赋值
    f := "apple"
    fmt.Println(f)
}

总结

使用 Go 语言变量的申明和使用变量。

附录

标签:变量,fmt,var,Println,0075,申明,Go
From: https://www.cnblogs.com/jiangbo4444/p/16840440.html

相关文章

  • 0076-Go-常量
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/constants目标使用Go语言的常量。示例packagemainimport("fmt""math")co......
  • 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库提供了解析命令行选项的能力,我们可以基于此来开发命令行工具。 假设我们想做一个命令行工具,我们通过参数提供【城市】,它自动能够返回当前......