Go Language programming

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Package indicates the packages where the source files are located

Func is used to define functions

Go is used in addition to the for-loop initialization, and most of the others do not need


There is no while loop in go, but you can use the for condition to simulate while

Compile:

Go Builde compiled file name

Define a variable, such as a string

var s string = ""

Go also automatically derives the type

var s = "";

You can also s:= ""

: = used in value declaration and initialization

Package    main07    Import (        "OS", "        flag"  /command line option Parser10    )    var Omitnewline = flag. Bool ("n", False, "Don t print final newline") +    const (        Space = ""        newline = "\ n")-    func ma In () {        flag. Parse ()   //Scans the ARG list and sets up Flags21        var s string = "", for        I: = 0; I < flag. Narg (); i++ {            If i > 0 {+                s + = Space25            }26            s + = flag. ARG (i)        }28        if!*omitnewline {            s + = Newline30        }31        os. Stdout.writestring (s) +    }

  

The go language is the same size as int, float, and int8,int32,int32, but unlike int, byte is the same size as int8, and the same type

S:= "string" is somewhat similar to the C-language char *str = "string", so that the contents of the string is not allowed to be modified, only the point of STR is changed

If you want to create a string that you can modify, you must use an array

declares an array s:= []int{1,2,3}

var arrayofint [3] int{1,2,3}, defines an array, but arrayofint cannot degenerate into a pointer

a:= [2][2]int{[2]int{1,2},[2]int{3,4}}

Slice

s:= [3]int{1,2,3};

SL = S[1:2];

Fmt. Printf ("%d\n", Sl[0])

Output is 2

The map in go uses make to create

You can use range to iterate through an array, Map,slice

For _;days = Range Monthdays {

Fmt. Printf ("%d\n", days);

}

Function:

def func (xs []int)

This function is passed in a splite instead of an array, when using this function: Fun (array[:]) instead of func (array), it will prompt that the array cannot be converted to []int

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.