Slices, Maps and Structs
Arrays and slices
var fixedArray [3]string = [3]string{"a", "b", "c"} // fixed size, rarely used directlynncourses := []string{"Go", "Python", "SQL"} // a slice -- resizable, used constantlyncourses = append(courses, "TypeScript")nfmt.Println(courses[0]) // Gonfmt.Println(len(courses)) // 4
A slice is a resizable, flexible view over an underlying array, and is what real Go code uses for lists almost universally — fixed-size arrays exist but are rarely reached for directly. append may return a new underlying array once the current one is full, which is why the convention is always courses = append(courses, ...), reassigning the result rather than assuming it modifies in place.
Maps
scores := map[string]int{n "Yash": 95,n "Ana": 88,n}nscores["Yash"] = 98nnvalue, exists := scores["Someone"]nif !exists {n fmt.Println("Not found")n}
A map is Go’s key-value type, directly comparable to a Python dict or a Java HashMap. The two-value form of a map lookup (value, exists := ...) is the idiomatic way to check whether a key is actually present, since a missing key otherwise just silently returns the type’s zero value (0 for an int) rather than an error.
Structs
type Course struct {n Title stringn LessonCount intn}nngoCourse := Course{Title: "Go", LessonCount: 7}nfmt.Println(goCourse.Title)
A struct groups related fields together — Go’s equivalent of a class’s data, without the class or inheritance machinery found in Java or C++. Go deliberately has no classes and no inheritance at all; behavior is attached separately via methods, covered in the next lesson.