How to print new line in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we are going to learn how we can print something in newline without using multiple fmt.Printf() method, here we will built-in syntax of go \n to print something in different lines.

if golang gets \n in your print statement then it will show in the next line.

Let’s see how we can use in fmt.Printf() method.

Here, basically, I’m writing "Go Hello \n World!" to print, now when go compile

it will show Go Hello in the first line and world! in the second line.

package main
import "fmt"

func main() {
	fmt.Printf("Go Hello \n World!")
}

Let’s see actual output of the code.

print, new line, golang

Try it yourself

All the best 👍

Follow me on Twitter