2. Toad Notes Go language--bag

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

2. Toad Notes Go language--bag

Each Go program is made up of packages.

The entry that runs the program is the package main.

This program uses and imports the package "FMT" and "Math/rand".

By convention, the package name is consistent with the last directory of the import path. For example, the "Math/rand" package is started by the Packages Rand statement

Code

Package Main

Import (

"FMT"

"Math/rand"

)

Func Main () {

Fmt. Println ("Myfavorite number is", Rand. INTN (10))

}

EXECUTE as follows:

Myfavorite number is 1

Import

The code uses parentheses to combine the imports, which is the "package" import statement.

You can also write multiple import statements, such as:

Import "FMT"
Import "Math"

However, using packaged import statements is a better form.

Guide Famous

After you have imported a package, you can call it with its exported name.

In Go, the name of the initial capital letter is exported.

Both Foo and Foo are the exported names. The name Foo is not exported.

Executes the code. Then add Math. Pi renamed to Math.PI and try to execute again, will error.

Package Main

Import (

"FMT"

"Math"

)

Func Main () {

Fmt. Println (Math. Pi)

}

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.