How do you write multi-line strings in Go?


The following snippet will print value of string variable in multiple lines.

Example

package main

import "fmt"

func main() {
	// ########## Multiline Exmaple 1 ###########
	
    multiLine1 := `Australia is a country and continent surrounded by the Indian and Pacific oceans. Its major cities
 – Sydney, Brisbane, Melbourne, Perth, Adelaide – are coastal. Its capital, Canberra, is inland. The country is 
known for its Sydney Opera House, the Great Barrier Reef, a vast interior desert wilderness called the Outback, 
and unique animal species like kangaroos and duck-billed platypuses.`
    fmt.Println(multiLine1)
	
	// ########## Multiline Exmaple 2 ###########
	multiline2 := "Line1 \n" +
				  "Line2 \n" +
				  "Line3 \n" +
				  "Line4"
    fmt.Print(multiline2)
}
Most Helpful This Week