String in golang
Strings are sequence of characters with definite length and can be created by enclosing in double quotes "Hello Go" and back ticks `Hello Go`. A string is a sequence of characters. Strings are the collection of individual bytes, where each character occupy single byte. Characters out of the ASCII characters (can say characters from other languages) occupy more than one byte. A string can be created by enclosing in double quotes "Hello Go" or backticks `Hello Go`. The difference between double quotes and backticks is that double quotes allow escape sequences like \n (newline) and \t (tab) and parses them but backticks don't. Example-1: package main import "fmt" func main( ) { fmt.Println(len("Hello Go")) fmt.Println("Hello Go"[1]) fmt.Println("Hello"+" "+"Go") } Output: 8 101 Hello Go Output Explained: fmt.Println(len("Hello Go"))
Comments