go--Basic Knowledge Learning One

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


Recently ready to start learning go, recorded here for easy review


1, first to download the installation deployment environment, we Google, a lot of great gods have relevant steps to explain, specific installation you can refer to the following website

Installation Reference address: http://www.cnblogs.com/custa/p/3913526.html

Go Download Address: https://golang.org/dl/

LZ download version of Windows, install, no need to configure environment variables

Liteide development tool Download Address: Http://www.golangtc.com/download/liteide

The relevant test code is posted directly below

Testpackage main//affirms that the introduction of the package import ("FMT" "math")//1, outside the function of this declaration is not allowed! , nothing outside the function must be added with the//XXX:=10//2 of Var func, two number, and return func add (a int, b int) int {return A + B}//3, multiple arguments are the same type, the preceding can be omitted, the last specified type can be func  ADDD (A, b int) int {return a + B}//4, function can have any number of return values Func swap (x, y String) (string, string) {return y, X}func split (sum int) (x, y int) {x = sum * 8/9y = sum-x//return statement with no argument returns the current value of the result. Which means ' direct ' return. Return//return x, Y}func main () {///5, two variable assignment forms are available, without assignment, the type corresponds to the default value, such as int default 0var a int = 1b: = 5var C, D boolfmt. Println ("Hello world!") Fmt. Println (A, B, C, D) var i, J int = 1, 2var js, python, Java = True, False, "no!" Fmt. Println (i, J, JS, Python, Java)//short declaration variable in a function, ': = ' A concise assignment statement can be used instead of the VAR definition where it is explicitly typed. Each statement outside the function must start with a keyword (' var ', ' func ', and so on), ': = ' structure cannot be used outside the function. JS, Python, Java: = True, False, "no!" Fmt. Println (Math. Pi) fmt. Println (Add ()) FMT. Println (ADDD (Ten)) E, F: = Swap ("SB", "BS") fmt. Println (E, f) fmt. Println (Split (10))//coercion type conversion//i: = 42//f: = float64 (i)//u: = UINT (f)//constant is defined with a const value that can be a character, String, Boolean, or numeric type. But constants cannot be used: = Syntax definitionConst PI = 3.14} 


The operation results are as follows

C:/go/bin/go.exe Build-i [C:/users/administrator] Success: Process exit code 0.c:/users/administrator/administrator.exe  [C:/ Users/administrator]hello world!1 5 False False1 2 true false no!3.1415926535897933030bs Sb8 2 success: Process exit code 0.



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.