Description
Go has different functions to output text, primarily in the `fmt` package. `Print`, `Println`, and `Printf` are the most common.
Pros & Cons
✅ Pros
- Formatting: `Printf` offers powerful C-style formatting.
❌ Cons
- None.
When to Use
Debugging and displaying information to standard output.
Example
Difference between Println and Printf.
package main
import "fmt"
func main() {
name := "John"
age := 30
fmt.Println("Hello World!") // Adds newline
fmt.Print("No newline here. ")
fmt.Printf("Name: %s, Age: %d\n", name, age) // Formatted
}
Best Practices
Use `%v` in `Printf` to print the default format of any value.
