This is a creation in Article, where the information may have evolved or changed. The 3rd chapter, variable var x string = "Hello, World" FMT. PRINTLN (x)
var x stringx = "Hello, World" FMT. PRINTLN (x)
var x string = "Hello"
var y string = "world"
Fmt. PRINTLN (x = = y)
Output false
x: = "Hello, ABC" FMT. PRINTLN (x) Short command to create variable or var x = "Hello, World"
var x int = 5
Variable scope scope constant const x string = "Hello, world" constant cannot be changed and then assigned value.
VAR (
A = 5
b = 10
c = 15
)
A multivalued variable that simply simplifies the amount of initialization code. Use the same as a single-valued variable. VAR (
A = 5
b = 10
c = 15
)
Fmt. Println (a)
Fmt. Println (b)
Fmt. Println (c)
If there are variables not using go will error: # command-line-arguments
. \floatcal.go:28:b declared and not used
. \floatcal.go:29:c declared and not used
Small program code: FMT. Print ("Please enter a number:")
var input float64
Fmt. SCANF ("%f", &input)
Fmt. Println (' 1
2
3
4
5
6
7
8
9
10 ')
The same is the multi-line output, note that the latter, the number 2 can not be preceded by a space or tab will be output.
I: = 1for i <= {fmt. PRINTLN (i) i = i + 1} can also be written like this:
For i: = 1; I <= 10; i++ {fmt. Println (i)}
Odd odd, even even if I% 2 = = 0 {fmt. Println (i, "even")} else {fmt. Println (i, "odd")}
Switch I {case 0:fmt. Println ("Zero") default:fmt. Println ("Unknow number")}
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.