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 itPrint()
– “Print” This cannot format anything, it simply takes a string and print itPrintln()
– “Print Line” same thing asPrintf()
however it will append a newline character\n