Lets Start With First Hello world Program

Part of Golang Mastery course

~15 min read
Interactive
Hands-on
Beginner-friendly

Lets Start With First Hello world Program#

example.go
string">"comment">// visit :- gopherlabs.kubedaily.com
package main
 
string">"comment">// main package declaration
import string">"fmt"
 
string">"comment">// import libraries
func main() {
string">"comment">// declare main function with func keyword followed by main()
fmt.Println(string">"Hello World")
string">"comment">// fmt is format
}
 
string">"comment">// output :- hello_world
 

Run in Go Playground →

  • A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name main and declare a function main that takes no arguments and returns no value.
example.go
func main() { ... }
 
  • Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete.

  • Go: Meaning of the 'fmt' package acronym
  • fmt is short for format.
  • Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler.

Your Progress

2 of 103 modules
2%
Started2% Complete
Previous
SpaceComplete
Next