0
0
Goprogramming~5 mins

Output using fmt.Print in Go

Choose your learning style9 modes available
Introduction

We use fmt.Print to show text or values on the screen. It helps us see what our program is doing.

When you want to show a message to the user.
When you want to check the value of a variable while coding.
When you want to print multiple values on the same line (no spaces or newline added automatically).
When you want to combine text and numbers in one line.
Syntax
Go
fmt.Print(value1, value2, ...)

fmt.Print prints the values without spaces or newline at the end.

You can print many values by separating them with commas.

Examples
Prints a simple text message.
Go
fmt.Print("Hello, world!")
Prints text and a number together without spaces added automatically.
Go
fmt.Print("Age: ", 25)
Prints two strings without spaces between them.
Go
fmt.Print("Go", "Lang")
Sample Program

This program prints the words "Hello, Go!" all together without spaces or new lines added automatically.

Go
package main

import "fmt"

func main() {
    fmt.Print("Hello")
    fmt.Print(", ")
    fmt.Print("Go")
    fmt.Print("!")
}
OutputSuccess
Important Notes

fmt.Print does not add spaces between arguments. For precise control over spacing, use multiple fmt.Print calls as shown, or fmt.Printf.

To print with a new line at the end, use fmt.Println instead.

Summary

fmt.Print shows text or values on the screen exactly as given.

It does not add spaces or new lines automatically.

Use commas to print multiple values together.