Your First Go Lab

GolangGolangBeginner
Practice Now

Introduction

Hi there, welcome to LabEx! In this first lab, you'll learn the classic "Hello, World!" program in Golang.

Click the Continue button below to start the lab.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL go(("`Golang`")) -.-> go/FunctionsandControlFlowGroup(["`Functions and Control Flow`"]) go/FunctionsandControlFlowGroup -.-> go/functions("`Functions`") subgraph Lab Skills go/functions -.-> lab-92714{{"`Your First Go Lab`"}} end

Hello Go

Write a program that prints the message "hello world" to the console.

  • The program should use the fmt package to print the message.
  • The program should be written in Golang.
## To run the program, put the code in `hello-world.go` and
## use `go run`.
$ go run hello-world.go
hello world

## Sometimes we'll want to build our programs into
## binaries. We can do this using `go build`.
$ go build hello-world.go
$ ls
hello-world hello-world.go

## We can then execute the built binary directly.
$ ./hello-world
hello world

## Now that we can run and build basic Go programs, let's
## learn more about the language.

There is the full code below:

// Our first program will print the classic "hello world"
// message. Here's the full source code.
package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

Summary

Coungratulations! You have completed your first LabEx Lab.

If you want to learn more about LabEx and how to use it, you can visit our Support Center . Or you can watch the video to learn more about LabEx.

Programming is a long journey, but Next Lab is just one click away. Let's do it!

Other Golang Tutorials you may like