Go Language learning Guide _golang

Source: Internet
Author: User
Tags lowercase

1. Import package, a main function has only a main function, contains a main package, the main function we want to declare the package of main!

Copy Code code as follows:

Package Main
Func Main () {
}

2. The introduction of package files, such as we are using FMT package, print Helloword, Golang has a definition of package visibility, such as private in other languages, protected these declarations. When the handwritten letter is lowercase is available in the package, outside the package can not be used, handwritten letter capitalization, reference to the package can be used! Give an example: FMT. PRINTLN () We will find that the functions we use and reference are all uppercase! The lowercase will call the wrong!

Copy Code code as follows:

Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello, cloud-dwelling community");
}

3. Packet obfuscation mechanism, we can package aliases, such as we feel that the package does not remember or say the package's name almost we use this alias mechanism!

Copy Code code as follows:

Package Main
Import str "FMT"
Package Main () {
Str. Println ("Hello, cloud-dwelling community");
}

4. Multiple packages, constants, global variables, general types, and other abbreviations. When we have multiple constants, packages, etc.

Copy Code code as follows:

Import (const (
"FMT" PI = "3.1415926" name =1
"NET" NAME = "Widuu" Age =12
"IO" age = "Wo" = "Me"
)               )                   )

Type of 5.Go

Copy Code code as follows:

BOOL Boolean has true false no 0 and 1
int integer based on platform customization if you're 32-bit, it's a 32-bit integer.
int8 8-bit integer in -128~256 this range is actually at 2 of the 8-side value, there is a symbol with negative numbers, uint8 is unsigned
Int16 16-bit integer
Rune 32-bit signed integral type
Int64 64-bit integer
FLOAT32/64 bit
complex64/complex128 Negative Type
Other types
Array Slice string
Reference type
Slice Map Chan
Interface type interface
Function type Func

5. The Declaration and assignment of variables and the value of the Declaration
We affirm that when there is no value, we will find such a
When declaring int float output is 0 declare bool output is false
Reference package math outputs the maximum value and the minimum value, such as the maximum Int16 value range of this output FMT. Println (Math. MaxInt16)

6. Type declaration We can customize type declarations, such as the following

Copy Code code as follows:

Package Main
Import Std "FMT"
Type text string
Func Main () {
var a text
A = "Hello"
Std. Println (a)
}

7. Type Conversion

View Source code Printing Help

Copy Code code as follows:

var a float32 = 100.01
B:=int (a)//output A is the value of 100.01 output B is 100
var c int = 65
D:=string (c)//output is a this is directly converted to the form of text a
B:=strconv. Itoa (c)//This output is 65 direct text output

Related Article

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.