GO Learning Notes (i)

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

1.Go programs are made up of packages. The entry that runs the program is the package main. The program uses and imports the package "FMT". The Go Language compilation runtime (go Run Xxx.go), the file must have the main package and the main function to run.

Package Mainimport ("FMT") func main () {FMT. Println ("hello!"))}

2. Function can have no parameters or accept multiple parameters

Func Add (x int, y int) int {    return x + y}func Add (x, y int) int {return x + Y}func main () {    fmt. Println (Add (1, 2))}
Func swap (x, y String) (string, string) {return y, X}func main () {A, B: = Swap ("Hello", "World") fmt. Println (A, B)}
Func split (sum int) (x, y int) {x = sum * 4/9 y = sum-x return}

Add Accept two + int the parameters of the type. ( Note that the type is after the variable name .) )

with no parameters return statement returns the current value of the result. i.e. ' direct ' return //func split return y

The 3.var statement defines a list of variables, like the argument list for a function, the type is behind

var c, Python, Java boolfunc Main () {var i intfmt. Println (i, C, Python, Java)}





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.