Go Language learning 2: First GO Program

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

I've always wondered why learning every language, starting with the first program is always Hello world, don't I write anything else, this language is not good to learn?

O (∩_∩) o haha ~, we do not delve into the here, or inherit the glorious tradition! The following is a completed Hello World program:


The package main ... ... ... ..... ... .... ... .... ... .... ..... .... ..... ..... ..... ..... ..... ..... .......-....... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 1
Import(... ...) ... ... .... ... .... ... .... ... .... ... .... ..... ..... ..... ..... .... ..... ..... .....-.....-........ ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... 2
 "FMT" ... ... ... ... ... ... ... ... ... ... .... ... .... ..... .... ..... ....., ..., ... and .... ..... ....? ....., ... and .... ....... ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... .. ..... ..... 3
)........................................................................................................................................................................ 4
FuncMain (){... ..... ... .... ... ..... ..... ..... ..... ..... ..... ....... .................. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 5
 FMT. Println ("Helloworld!") .............................................................................. 6
}........................................................................................................................................................................ 7
Compile, the output after running is:

Hello world!

Let's analyze one of these codes (the numbers below represent the line numbers of the code):

1 should be like Java, put this file into a package, the registration is called Main

2 is the library file that imports the system

3 Use the Func key to define the function, and the Go Language program entry is the main function

4 calling the library function output string Hello World, note here: The go language rules, all exported functions or variables, the first letter must be capitalized.

It is also important to note that the Go Language program statement does not require a semicolon as a terminator.

Let's change this function:

The output of the program is:
Here are a few points of knowledge:
1. When there are multiple libraries that need to be imported, you can either have one () or import them separately:
2. The parameters of the function and the type of the return value are all back-mounted

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.