CodeBlanks Logo Icon CodeBlanks

Summary - Go basics

Combine package, fmt and comments to write your first Go program.

Summary - Go basics

In this section you learned the building blocks of Go:

  • package main for an executable program
  • import "fmt" to bring in a package
  • func main() as the entry point
  • fmt.Println to print to the screen
  • // and /* */ for comments

Now you will combine these concepts by writing a small program.

Practice Write a welcome message

Add a fmt.Println line inside the empty main. The output must be Welcome to Go.

Starter code

main.go
package main

import "fmt"

func main() {
    // buraya yaz
}

Sample solution

main.go
package main

import "fmt"

func main() {
    fmt.Println("Welcome to Go")
}

Expected output

Go'ya hoş geldin

Practice Commented welcome

Add a // comment to the program and produce the output Let us start with fmt.Println.

Starter code

main.go
package main

import "fmt"

func main() {
    return
}

Sample solution

main.go
package main

import "fmt"

func main() {
    // Welcome message
    fmt.Println("Let us start")
}

Expected output

Haydi başlayalım

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Program skeleton

Question
package main

import "fmt"

func ____() {
    fmt.Println("Ready")
}
Answer
package main

import "fmt"

func main() {
    fmt.Println("Ready")
}

Explanation: The main function is the entry point.

2 Match the section concepts

Term Meaning
package main Executable package
import "fmt" Package import
func main() Entry point
fmt.Println Prints to screen

All lessons in Beginner