Println vs Printf vs Print in Go





Hey guys in this post, we will discuss the difference between Println(), Printf() and Print() methods with examples.

1. Create a directory


mkdir go-workspace

2. Move inside the directory


cd go-workspace

3. Create an empty file


code PrintMessages.go

Keyword code represents Visual studio code, it will open the file inside the Visual studio code.

Note: I will be using Visual studio code for writing code but you can use any other text editors or IDEs for writing code.

4. Write the code


package main

import "fmt"

func main() {
	fmt.Println("Hello World")
	fmt.Printf("My name is %s. ", "Bushan")
	fmt.Print("I am from ")
	fmt.Print("India")
}
  • Printf() – “Print Formatter” this function allows you to format numbers, variables and strings into the first string parameter you give it
  • Print() – “Print” This cannot format anything, it simply takes a string and print it
  • Println() – “Print Line” same thing as Printf() however it will append a newline character\n




About the author

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

View all posts

Leave a Reply

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