Created
March 8, 2021 08:46
-
-
Save yarimadam/d12028fa3e2bb42c6c98263b191e13c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
brands := []string{"Mercedes", "Dodge", "Vauxhall"} | |
fmt.Println("== All Brands") | |
fmt.Println(brands) | |
fmt.Println("== Variable Type") | |
fmt.Println(fmt.Printf("Type: %T", brands)) | |
fmt.Println("== First Brand") | |
fmt.Println(brands[0]) | |
fmt.Println("== All Except First") | |
fmt.Println(brands[1:]) | |
fmt.Println("== All Except Last") | |
fmt.Println(brands[:len(brands)-1]) | |
fmt.Println("== One Brand Per Line With Index") | |
for i, name := range brands { | |
fmt.Println(fmt.Printf("%T", i)) | |
fmt.Println(fmt.Printf("Brand: %s, Index: %v", name, i)) | |
} | |
fmt.Println("== One Brand Per Line") | |
for _, name := range brands { | |
fmt.Println(name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment