Go Learning 1:hello World

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
<pre class= "plain" name= "code" >package mainimport ("FMT" "OS" "strings") func main () {who: = "world!"//define variable Whoif len (OS. Args) > 1 {who = strings. Join (OS. Args[1:], "")}fmt. Println ("Hello", who)//output}


Go language uses C + + annotation style
    All the go language codes can only be placed in one package, and each go program must contain a main package and a main () function. The main () function acts as the entry for the entire program and is executed first when the program is run. In fact, the package in the go language may also include the Init () function, which is executed before the main () function.
    There is no naming conflict between package name and function name.
    The go language-oriented processing unit is a package, not a file, which means that the package can be split into any number of files. In the Go compiler's view, if all of these files have the same package declaration, then they belong to a package, which is the same as putting everything in a single file.
    The import statement imports the packages from 3 standard libraries:
        The FMT package provides functions for formatting text and reading text into the format,
        OS Package provides cross-platform OS-level variables and functions
        The strings package provides functions for handling strings
    The basic type of the go language supports commonly used operators such as "+" for numeric addition operators and string link operations, while the standard library of the Go language complements these operations with packages that have various functions, such as: strings. You can also give these basic classes the ability to create your own types, or add custom methods for those types.
    In the go language, code blocks that contain function bodies and control structures use curly braces as boundary characters. Technically speaking, the statements of the go language are separated, but these are automatically added by the compiler without manual input, unless you need to write multiple statements on the same line.
    The functions and methods of the go language are defined by the keyword func.
    : = In the go language is called the birth of a fast variable, the first line in the main () function declares and initializes a variable at the same time. Go is a strongly-typed language.

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.