0
0
Goprogramming~10 mins

Output using fmt.Print in Go - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Output using fmt.Print
Start program
Call fmt.Print
Evaluate arguments
Write output to console
Continue or end program
The program starts, calls fmt.Print with arguments, evaluates them, writes output to the console, then continues or ends.
Execution Sample
Go
package main
import "fmt"
func main() {
    fmt.Print("Hello, ", "world!")
}
This code prints "Hello, world!" to the console without a newline.
Execution Table
StepActionEvaluationOutput
1Start programN/A
2Call fmt.Print with arguments "Hello, ", "world!"Arguments evaluated as "Hello, " and "world!"
3fmt.Print writes to consoleConcatenate arguments to "Hello, world!"Hello, world!
4End of main functionProgram ends
💡 Program ends after printing output without newline
Variable Tracker
VariableStartAfter fmt.PrintFinal
output"""Hello, world!""Hello, world!"
Key Moments - 2 Insights
Why doesn't fmt.Print add a newline after printing?
fmt.Print outputs exactly what you give it without adding a newline, as shown in execution_table step 3 where output is "Hello, world!" without extra line breaks.
What happens if multiple arguments are passed to fmt.Print?
fmt.Print concatenates all arguments as strings without spaces or newlines, as seen in step 2 and 3 where "Hello, " and "world!" are combined directly.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output after step 3?
A"Hello world"
B"Hello, world!\n"
C"Hello, world!"
D"Hello, "
💡 Hint
Check the Output column in execution_table row 3
At which step does fmt.Print evaluate its arguments?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the Action and Evaluation columns in execution_table row 2
If you want to add a newline after output, which function should you use instead of fmt.Print?
Afmt.Print
Bfmt.Println
Cfmt.PrintLine
Dfmt.WriteLine
💡 Hint
Recall that fmt.Print does not add newline; fmt.Println does
Concept Snapshot
fmt.Print outputs text to the console exactly as given.
It takes multiple arguments and concatenates them without spaces or newlines.
No newline is added after printing.
Use fmt.Println to add a newline automatically.
Syntax: fmt.Print(arg1, arg2, ...)
Full Transcript
This example shows how fmt.Print works in Go. The program starts and calls fmt.Print with two string arguments: "Hello, " and "world!". fmt.Print evaluates these arguments and writes them directly to the console without adding a newline. The output is exactly "Hello, world!". The program then ends. fmt.Print does not add spaces or newlines between arguments or after output. To add a newline, use fmt.Println instead.