This commit is contained in:
2024-10-23 12:10:32 +00:00
parent c7e45139ec
commit a8148f2400
8 changed files with 230 additions and 5 deletions

3
lists/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module example.com/lists
go 1.23.1

33
lists/main.go Normal file
View File

@@ -0,0 +1,33 @@
package main
import "fmt"
type floatMap map[string]float64
func (m floatMap) output() {
fmt.Println(m)
}
func main() {
userNames := make([]string, 2, 5)
userNames[0] = "Julie"
userNames = append(userNames, "Max")
userNames = append(userNames, "Manuel")
fmt.Println(userNames)
courseRatings := make(floatMap, 3)
courseRatings["go"] = 4.7
courseRatings["react"] = 4.8
courseRatings["angular"] = 4.7
courseRatings.output()
for index, value := range userNames {
fmt.Println("Index:", index)
fmt.Println("Value:", value)
}
}

18
lists/maps/maps.go Normal file
View File

@@ -0,0 +1,18 @@
package maps
import "fmt"
func main() {
websites := map[string]string{
"Google": "https://google.com",
"Amazon Web Services": "https://aws.com",
}
fmt.Println(websites)
fmt.Println(websites["Amazon Web Services"])
websites["LinkedIn"] = "https://linkedin.com"
fmt.Println(websites)
delete(websites, "Google")
fmt.Println(websites)
}

35
lists/slices/lists.go Normal file
View File

@@ -0,0 +1,35 @@
package lists
import "fmt"
func main () {
prices := []float64{10.99, 8.99}
fmt.Println(prices[0:1])
prices[1] = 9.99
prices = append(prices, 5.99, 12.99, 29.99, 100.10)
prices = prices[1:]
fmt.Println(prices)
discountedPrices := []float64{101.99, 80.99, 20.99}
prices = append(prices, discountedPrices...)
fmt.Println(prices)
}
// func main() {
// var productNames [4]string = [4]string{"A book"}
// prices := [4]float64{10.99, 9.99, 45.99, 20.0}
// fmt.Println(prices)
// fmt.Println(productNames)
// productNames[2] = "A carpet"
// fmt.Println(prices[2])
// featuredPrices := prices[1:]
// featuredPrices[0] = 199.99
// highlightedPrices := featuredPrices[:1]
// fmt.Println(highlightedPrices)
// fmt.Println(prices)
// fmt.Println(len(highlightedPrices), cap(highlightedPrices))
// }