Go-Grundlagen

Hello World in Go: Structure of a Program

Write your first Go program and see what each part does: package main, import and func main.

  • Einsteiger
  • 2 Min. Lesezeit
  • 1 ausführbares Beispiel
Das lernst du
  • package main and func main
  • Importing fmt
  • Printing with fmt.Println
From source to output
  1. 1main.goYou write the code
  2. 2go runGo compiles and starts it
  3. 3main()The program starts in main
  4. 4Hello, Go!The text appears

How a Go program runs

Every Go file starts with a package name. A program that you can run lives in package main and starts in the function main. import brings in other packages, such as fmt for printing.

fmt.Println prints its arguments and ends the line. Names that start with a capital letter, such as Println, are the ones a package makes available to other packages.

Das Wichtigste

  1. A runnable program lives in package main.
  2. It starts in func main.
  3. fmt.Println prints a line of text.

Ausführbares Go-Beispiel

Go
Code ausführen →
main.go
package main

import "fmt"

func main() {
	fmt.Println("Hello, Go!")
}
Run-Button für dieses Beispiel erstellen Ergebnis der Ausführung
Hello, Go!

Üben

Öffne das Beispiel im Online-Compiler, ändere einen Wert oder füge eine Zeile hinzu und sage die Ausgabe voraus, bevor du es ausführst. Bring den Code danach absichtlich zum Scheitern und lies die Meldung des Compilers.

Lektion fertig?

Markiere sie als gelernt, um deinen Fortschritt zu verfolgen.

Weiter: Variables and Constants →

Mit einer Challenge üben

Nutze den Inhalt dieser Lektion, um ein echtes Problem zu lösen. Jede Challenge läuft im Browser, mit sofortigen Tests und einem KI-Review.

Alle Challenges