Go Language Basics (i)

Source: Internet
Author: User
Tags bitwise bitwise operators

Distinguishing features from other languages: clear and concise, parallel (line and Goroutines), Channel, fast, secure, standard format, type back (var a int), UTF-8, open source, happy Erlang[7] and Go are functionally similar in part. The main difference between Erlang and go is that Erlang is a functional language, and go is imperative. Erlang runs on a virtual machine, while Go is compiled. Go used to feel closer to unix  II, Hello worldpackage mainimort "FMT"//Implement formatted I/o/*print Something*/func main () {FMT. Printf ("hello,word\n");}   NOTE: Packagemain must first appear, followed by import. In go, the package always appears first, then import, then everything else. When the Go program executes, the function that is called First is Main.main (), which is inherited from C.   Compile and run code%go build Helloworld.go generates an executable file called HelloWorld%./hellowordhello,world  three variables, to declare the after assignment var a int declaration a =15 Assignment is equivalent to a: =15 directly declares and assigns   multiple variables: var (x intb bool) or, if all are integers, you can declare Var, a, B int parallel assignment A, c: =, 16  Note: If you want to write two (or more) statements on one line , they must be separated by semicolons (';'). In general, you do not need a semicolon a special variable name is _ (underscore). Any value assigned to it is discarded. In this example, assign a value of 35 to B and discard 34 at the same time. _, B: = 35Go compiler for declared unused variables in error   Four, variable type 1, Boolean type True and FALSE2, numeric type int, you can use Int32 or UInt32. The complete list of integer types (symbols and unsigned) is Int8,int16,int32,int64 and Byte,uint8,uint16,uint32, UInt64. Byte is the alias of Uint8. Values for floating-point types are float32 and float64  Note: Assignments can be made in octal, hexadecimal, or scientific notation: 077,0XFF,1E3 or 6.022e23 these are all legal.  3, Constant const x=4const (a = 0←is an int now b string = "0")  4, string s: = "Hello world!" must be double quotes or var s string = "hel Lo "NOTE: Once the variable is assigned, the string cannot modify the multiline string: s: =" Starting part "+" ending part "is converted to: s: =" starting "; +" ending "; this is the wrong syntax and should be written like this: S: = "starting" + "ending part" another way is to use anti-quote ' as the original string symbol: s: = ' starting part ending '   Another: Runerune is the alias of Int32. Encode with UTF-8. When is this type used? for example, you need to traverse characters in a string. You can loop through each byte (only if you use US ASCII-encoded strings with characters equivalent, and they don't exist in Go!). So in order to get the actual characters, you need to use the Rune type.  5, complex number its variable type is complex128 (64-bit virtual part). If smaller is needed, there is also the imaginary part of the complex64–32 bit. The complex number is written as Re + Imi,re is the real part, IM is the imaginary part, and I is the mark ' I ' (√?1). An example of using a complex number: var c complex64 = 5+5i;fmt. Printf ("Value is:%v", c) will print: (5+5i)  6, error Go has a built-in type that exists for error, called error. var a error defines a as a error,a value of nil.    v. Operators and built-in functions  +-*/and% will work as you expect,& | ^ and &^ represent bitwise operators bitwise AND, bitwise OR, bitwise XOR, and bit clear. && | | The operators are logical and logical OR. Not listed in the table is the logical non:!. While Go does not support operator overloading (or method overloading), some built-in operators support overloading.  GO reserved word:      

Go Language Basics (i)

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.