02.Golang Learning Hello World

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
    1. Source code example (Bo Master is Liteide,gopath is directly in the IDE, view-and management Gopath added)

Package Mainimport "FMT" Func Main () {FMT. Printf ("Hello World")} Compiled output: Hello World success: Process exit code 0.

2. Code explanation

In the first row

Package main//This line is required, so the go file is in the packages <something> start,//to declare which packet this file belongs to. For standalone files, the package main must start with the same

In the second row

Import "FMT"//Represents the imported package, where the print function in the FMT package is used, so the package must be imported. This is the same as importing packages in Java//If you need to use more than one package: import ("FMT" "bytes" "io") can also: import "fmt", "bytes", "IO"

In the third row

The func//keyword is used to define a function, such as if you want to write a demo function yourself, it should be defined as: Func demo () {//other code}//the third row of main () is roughly the same as in other languages

In line four

Fmt. printf ()//Use the printf function in the FMT package, which is a print function. In a custom package, generally speaking, the package name should be lowercase, the function capital begins with the object-oriented public function, the function starts with lowercase, the equivalent of the private function


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.