A Tour of Go Short variable declarations

Inside a function, the := short assignment statement can be used in place of a var declaration with implicit type.

Outside a function, every construct begins with a keyword (varfunc, and so on) and the := construct is not available.

package main 

import "fmt"

var k int = 3
var k2 = 3
//k3 := 4 //non-declaration statement outside function body
func main() {
    var i, j int = 1, 2
    k := 3
    c, python, java := true, false, "no!"
    fmt.Println(i, j, k, c, python, java)
}
时间: 2024-07-30 13:48:37

A Tour of Go Short variable declarations的相关文章

[转]50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs

http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/ 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs Go is a simple and fun language, but, like any other language, it has a few gotchas... Many of those gotc

译:go’s block and identifiers scope

go 代码块和标识符作用域 (go's  block and identifiersscope) 一.      Blocks A block is a possibly empty sequence of declarations andstatements within matching brace brackets. 语句块(blocks)由闭合的大括号包裹,里面可能包含空的声明或者语句:block与作用域密切相关,见下章节. Block = "{" StatementList

golang基础练习(一)

//遍历map package main import "fmt" func main() { x := make(map[string]int) x["zhangsan"] = 3 x["lisi"] = 4 x["wangwu"] = 5 //#丢弃值 for i,_ := range x { fmt.Println(i) } } //匿名函数 package main import "fmt" fun

Codeforces Gym 100513M M. Variable Shadowing 暴力

M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/M Description In computer programming, variable shadowing occurs when a variable declared within a certain scope has the same name as a variab

C++ Core Guidelines

C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very early draft. It is inkorrekt, incompleat, and pµøoorly formatted. Had it been an open source (code) project, this would have been release 0.6. Copy

coffeescript 1.8.0 documents

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule

Extending JavaScript Natives

Most built-in JavaScript types are constructors whose prototypes contain the methods and other properties that define their default behavior: //(results will vary by browser) Object.getOwnPropertyNames(Function.prototype) //["bind", "argume

JAVASCRIPT的一些知识点梳理

春节闲点,可以安心的梳理一下以前不是很清楚的东东.. 看的是以下几个URL: http://web.jobbole.com/82520/ http://blog.csdn.net/luoweifu/article/details/41466537 http://javascriptissexy.com/understand-javascript-closures-with-ease/ http://javascriptissexy.com/javascript-variable-scope-an

PLSQL Coding Standard

Naming and Coding Standards for SQL and PL/SQL "The nice thing about standards is that you have so many to choose from." - Andrew S Tanenbaum Introduction This document is mentioned in a discussion on the OTN forums. One of the first comments be