07. Go Playground

Run without installing!

The Go Playground is a web service that runs on golang.org's servers.

We can use Go playground to edit and run simple Go programs. Head to playground at : https://play.golang.org/

Delete existing code and type in below code manually. (Remember programming is all about muscle memory!)

hello.go
package main

import "fmt"

func main() {
	fmt.Println("Hello, Pune!")
}

Let's understand how this code works:

Every Go program starts execution from main()

func main(){}

Main is the signal to compiler to start execution of code from here. This is entry point of our application.

Every Go program should be part of a package

package main

This declares that our program is part of package "main". Packages are used to bundle similar code that can be reused easily.

Go program can use external packages using import

import "fmt"

We are importing fmt package using import statement. Compiler will find this package and import in our program before we can use it.

We are using Println method from fmt package to print output to console. How to print output to console is implemented by fmt package, we do not have to write (re-write!) code to do it!

Last updated