Go Language Violence Primer 3-variables

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

About the author

Program developers, not confined to language and technology, are currently mainly engaged in PHP and front-end development, using the Laravel and Vuejs,app end use Apicloud hybrid development. The right and enough is the never-ending pursuit. 2017.05.04 start learning go language in free time

Personal website: http://www.linganmin.cn

Recently wrote a mobile phone online play H5 movie station: Http://www.ifilm.ltd

package main/** * 声明变量方式 */// 第一种,指定变量类型,声明后赋值,若不赋值使用默认值var name string = "saboran"var age int // 默认值为0var address string // 默认值为空字符串// 第二种,根据值自行判断类型var sex = "male"var sister = 2// 第三种,省略var, := 左侧的变量不应该是已经声明过的,否则会编译错误//sex := "male" // 这种声明方式只能用在函数内部,否则编译报错/** * 多变量声明 */// 声明多个变量,自动判断类型var friendName, friendAge = "lingan",18// 声明多个变量,指定类型var (    friendSex string    firendSister int)func main() {    // 第一种定义的输出    println(name)    println(age)    println(address)    // 第二种定义的输出    println(sex)    println(sister)    // 第三种定义输出    // 声明初始化多个变量输出    println(friendName)    println(friendAge)}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.