We already know about the last chapter. The basic structure of The 6 tags are (one per line): In If you plan to write multiple statements on the same line, they must use the Here are two statements: Comments will not be compiled, and each package should have related comments. Single-line comments are the most common form of comments, and you can use them anywhere with Identifiers are used to name variables, types, and other program entities. An identifier is actually a sequence of one or more letters (AbeliZ and axiz) numbers (0,9) and underscores _, but the first character must be a letter or underscore, not a number. The following are valid identifiers: The following are invalid identifiers: The string of the The output result of the above example is: The following is listed Break Default Func Interface Select Case defer Go Map Struct Chan Else Goto Package switch Const Fallthrough If Range Type Continue For Import Return Var In addition to the keywords introduced above Append Bool Byte Cap Close Complex Complex64 Complex128 Uint16 Copy False Float32 Float64 Imag Int Int8 Int16 uint32 Int32 Int64 Iota Len Make New Nil Panic Uint64 Print Println Real Recover string True Uint Uint8 Uintptr Programs generally consist of keywords, constants, variables, operators, types, and functions. These delimiters may be used in the program: parentheses These punctuation marks may be used in the program: The declaration of variables in the The proper use of spaces in the statement can make the program easier to read. No spaces: Add a space between variables and operators to make the program look more beautiful, such as: The output is as follows:
Go
language, which we will learn in this chapter
Go
basic grammar of the language. 2.4.1. Go marker #
Go
program can be composed of multiple tags, which can be keywords, identifiers, constants, strings, and symbols. As follows
GO
statement consists of six tags:fmt.Println("Hello, World!")
1. fmt
2. .
3. Println
4. (
5. "Hello, World!"
6. )
2.4.2. Line delimiter #
Go
a program, one line represents the end of a statement. Each statement does not need to be like
C
other languages in the family use semicolons as well.
;
at the end, because all of this work will be done by
Go
compiler completes automatically.
;
artificial distinction, but in actual development, we do not encourage this practice.fmt.Println("Hello, World!")
fmt.Println("Novice Tutorial:runoob.com")
2.4.3. Annotation #
//
single-line comment at the beginning. Multiline comments, also known as block comments, have been marked with
/*
start with a
*/
end. Such as:// Single-Line Comments
/*
Author by Novice Tutorial
I am a multi line comment
*/
2.4.4. Identifier #
mahesh kumar abc move_name a_123
myname50 _temp j a23b9 retVal
1ab
(starts with a number)
case
(
Go
keywords of language)
a+b
(operators are not allowed) 2.4.5. String concatenation #
Go
language can be passed through the
+
:Example #
package main
import "fmt"
func main() {
fmt.Println("Google" + "Runoob")
}
GoogleRunoob
2.4.6. Keyword #
Go
25 keywords or reserved words that will be used in the code:
Go
language also has 36 predefined identifiers:
()
, square brackets
[]
and curly braces
{}
.
.
,
,
,
;
:
and
...
. 2.4.7. Spaces in Go language #
Go
language must be separated by spaces, such as:var age int;
fruit=apples+oranges;
fruit = apples + oranges;
2.4.8. Format string #
Go
use in language
fmt.Sprintf
format the string and assign a value to the new string:Example #
package main
import (
"fmt"
)
func main() {
// %d represents an integer number, %s represents a string
var stockcode=123
var enddate="2020-12-31"
var url="Code=%d&endDate=%s"
var target_url=fmt.Sprintf(url,stockcode,enddate)
fmt.Println(target_url)
}
Code=123&endDate=2020-12-31