Go Printing to Stdout and Stderr: Difference between revisions
Jump to navigation
Jump to search
(32 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* [[Go_Language#Printing|Go Language]] | * [[Go_Language#Printing|Go Language]] | ||
* [[Go Code Examples#Code_Examples|Go Code Examples]] | * [[Go Code Examples#Code_Examples|Go Code Examples]] | ||
* [[Go Package fmt|The <tt>fmt</tt> Package]] | |||
=Bootstrapping Functions= | |||
Both <code>[[#print.28.29|print()]]</code> and <code>[[#println.28.29|println()]]</code> are [[Go_Language#Pre-Declared_Functions|pre-declared functions]], ready to use without any import. | |||
<font color=darkkhaki>TODO: https://golang.org/ref/spec#Bootstrapping</font> | |||
==<tt>print()</tt>== | |||
==<tt>println()</tt>== | |||
<syntaxhighlight lang='go'> | |||
func main() { | |||
println("something") | |||
} | |||
</syntaxhighlight> | |||
=<tt>fmt</tt> Functions= | |||
{{Internal|Go_Package_fmt|The <tt>fmt</tt> Package}} | |||
==<tt>fmt.Printf()</tt>== | |||
{{External|https://golang.org/pkg/fmt/#Printf}} | |||
<syntaxhighlight lang='go'> | |||
import "fmt" | |||
// ... | |||
fmt.Printf("something %s", "blue") | |||
</syntaxhighlight> | |||
<code>Print()</code> expects a '''format specifier''' (or a '''format string''') as the first argument, which contains [[Go_Package_fmt#Conversion_Characters|conversion characters]] (ex. <code>%s</code>). {{Internal|Go_Package_fmt#Conversion_Characters|Format String | Conversion Characters}} |
Latest revision as of 22:00, 22 December 2023
Internal
Bootstrapping Functions
Both print()
and println()
are pre-declared functions, ready to use without any import.
TODO: https://golang.org/ref/spec#Bootstrapping
print()
println()
func main() {
println("something")
}
fmt Functions
fmt.Printf()
import "fmt"
// ...
fmt.Printf("something %s", "blue")
Print()
expects a format specifier (or a format string) as the first argument, which contains conversion characters (ex. %s
).