0
0
Goprogramming~5 mins

Output using fmt.Println in Go

Choose your learning style9 modes available
Introduction

We use fmt.Println to show messages or results on the screen. It helps us see what our program is doing.

To display a greeting message to the user.
To show the result of a calculation.
To print debugging information while writing code.
To output text or numbers during program execution.
To separate lines of output clearly.
Syntax
Go
fmt.Println(value1, value2, ...)

fmt.Println prints each value separated by a space and adds a new line at the end.

You can print many values at once by separating them with commas.

Examples
Prints a simple text message.
Go
fmt.Println("Hello, world!")
Prints multiple numbers separated by spaces.
Go
fmt.Println(10, 20, 30)
Prints a label and the result of a calculation.
Go
fmt.Println("Sum:", 5+3)
Sample Program

This program prints three lines: a welcome message, a number with a label, and a goodbye message.

Go
package main

import "fmt"

func main() {
    fmt.Println("Welcome to Go programming!")
    fmt.Println("The answer is", 42)
    fmt.Println("Goodbye!")
}
OutputSuccess
Important Notes

Always import fmt to use fmt.Println.

fmt.Println automatically adds a new line after printing.

Use commas to print multiple values with spaces in between.

Summary

fmt.Println prints text or values to the screen with a new line.

You can print many things at once by separating them with commas.

It is useful for showing messages, results, or debugging information.