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.
Das lernst du
- package main and func main
- Importing fmt
- Printing with fmt.Println
From source to output
- 1
main.goYou write the code - 2
go runGo compiles and starts it - 3
main()The program starts in main - 4
Hello, 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
- A runnable program lives in package main.
- It starts in func main.
fmt.Printlnprints a line of text.
Ausführbares Go-Beispiel
main.go
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
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.
Dein Fortschritt ist in diesem Browser gespeichert Melde dich an, um ihn auf jedem Gerät zu behalten.
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.
- Ungerade, Gerade oder Keines von beidem Klassifiziere eine Zahl danach, ob sie eine ungerade ganze Zahl, eine gerade ganze Zahl oder keines von beidem ist. Einfach
- Quadrat einer Zahl Multipliziere eine ganze Zahl mit sich selbst. Einfach