G
Grundlegende Syntax
Go Syntax Guide
Go grundlegende Syntax und Struktur
Grundlegende Syntax
Go grundlegende Syntax und Struktur
Go grundlegende syntax (go)
package main
import (
"fmt"
"math"
)
// Main function - entry point
func main() {
// Variables
var name string = "John"
age := 25 // Short variable declaration
height := 1.75
// Constants
const PI = 3.14159
const (
Sunday = iota // 0
Monday // 1
Tuesday // 2
)
// Arrays
var numbers [5]int = [5]int{1, 2, 3, 4, 5}
names := [3]string{"Alice", "Bob", "Charlie"}
// Slices (dynamic arrays)
var slice []int
slice = append(slice, 1, 2, 3)
dynamicSlice := []int{4, 5, 6}
// Maps
person := map[string]interface{}{
"name": "John",
"age": 25,
"active": true,
}
// Printing
fmt.Println("Hello, World!")
fmt.Printf("Name: %s, Age: %d\n", name, age)
fmt.Printf("PI: %.2f\n", PI)
fmt.Printf("Square root of 16: %.2f\n", math.Sqrt(16))
// Loops
for i := 0; i < len(numbers); i++ {
fmt.Printf("numbers[%d] = %d\n", i, numbers[i])
}
// Range loop
for index, value := range slice {
fmt.Printf("slice[%d] = %d\n", index, value)
}
// Map iteration
for key, value := range person {
fmt.Printf("%s: %v\n", key, value)
}
}
Explanation
Go verwendet Pakete für Organisation. Die main-Funktion ist der Einstiegspunkt. Go hat Arrays, Slices und Maps als eingebaute Datenstrukturen.
Common Use Cases
- Systemprogrammierung
- Webserver
- CLI-Tools
- Microservices
Related Go Syntax
Master Grundlegende Syntax in Go
Understanding Grundlegende Syntax is fundamental to writing clean and efficient Go code. This comprehensive guide provides you with practical examples and detailed explanations to help you master this important concept.
Whether you're a beginner learning the basics or an experienced developer looking to refresh your knowledge, our examples cover real-world scenarios and best practices for using Grundlegende Syntax effectively in your Go projects.
Key Takeaways
- Systemprogrammierung
- Webserver
- CLI-Tools