1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
mySlice := []int{1, 2, 3, 4} subSlice := mySlice[1:3] reversedSlice := reverseSlice(mySlice)
myMap := map[string]interface{}{ "name": "Alice", "age": 30, }
import "container/list" myList := list.New() myList.PushBack(1) myList.PushBack(2) myList.PushBack(3)
import "container/heap" maxHeap := &MaxHeap{} minHeap := &MinHeap{}
myString := "Hello, World!" substring := myString[7:12] myInt := 42 myStr := fmt.Sprintf("%d", myInt)
originalSlice := []int{1, 2, 3, 4} shallowCopy := make([]int, len(originalSlice)) copy(shallowCopy, originalSlice) deepCopy := append([]int(nil), originalSlice...)
index := 1 mySlice = append(mySlice[:index], mySlice[index+1:]...)
containsLowercase := false for _, char := range myString { if unicode.IsLower(char) { containsLowercase = true break } }
for _, item := range mySlice { fmt.Println(item) }
for key, value := range myMap { fmt.Println(key, value) }
if _, exists := myMap["name"]; exists { fmt.Println("Map contains 'name'") }
|