Section10-80

This commit is contained in:
2023-11-09 11:13:14 +01:00
parent 59ffa2443a
commit 40b6e50a16
2 changed files with 69 additions and 0 deletions

34
Section10/78.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import "fmt"
func main() {
var cities []string
fmt.Println("cities is equal to nil: ", cities == nil)
fmt.Printf("cities %#v\n", cities)
fmt.Println(len(cities))
numbers := []int{21, 13, 54, 95}
fmt.Println(numbers)
nums := make([]int, 2)
fmt.Printf("%#v\n", nums)
type names []string
friends := names{"Dan", "Maria"}
fmt.Println(friends)
myFriend := friends[0]
fmt.Println("My best friend is ", myFriend)
friends[0] = "Gabi"
fmt.Println("My best friend is ", friends[0])
for index, value := range numbers {
fmt.Printf("index: %v, value: %v\n", index, value)
}
var n []int
n = numbers
fmt.Println(n)
}

35
Section10/79.go Normal file
View File

@@ -0,0 +1,35 @@
package main
import "fmt"
func main() {
var n []int
fmt.Println(n == nil)
m := []int{}
fmt.Println(m == nil)
a, b := []int{1, 2, 3}, []int{1, 2, 3}
//fmt.Println(a == b)
var eq bool = true
a = nil
for i, valueA := range a {
if valueA != b[i] {
eq = false
break
}
}
if len(a) != len(b) {
eq = false
}
if eq {
fmt.Println("a and b slices are equal")
} else {
fmt.Println("a and b slices are not equal")
}
}