Menu Close

Go – Difference between Print() and Println() function in go

We are going to learn about difference between Print() and Println() function in go. We will also see how to use and import Print() and Println().

Difference between Print() and Println() methods:

  • Print() method simply takes the string and print it in a single line.
  • Println() method takes the string and append a new line character ‘\n’ at the end of string.

Print() and Println() methods are come under fmt package in go.

Syntax:

Print():

func Print(a ...interface{}) (n int, err error)


Println():

func Println(a ...interface{}) (n int, err error)

Print() function example:

package main

import (

  "fmt"

)

func main() {

  fmt.Print("Hello ")

  fmt.Print("Hii")

}

Output:

Hello Hii

Println() function with example:

package main

import (

  "fmt"

)

func main() {

  fmt.Println("Hello ")

  fmt.Println("Hii")

}

Output:

Hello

Hii

To learn more about golang, You can refer given below link:

https://techieindoor.com/go-lang-tutorial/

References:

 https://golang.org/doc/
https://golang.org/pkg/
https://golang.org/pkg/fmt/
https://golang.org/pkg/fmt/#Println
Posted in golang, Miscellaneous

Leave a Reply

Your email address will not be published. Required fields are marked *