Avatar ·

What are the differences between fmt.Println() and println() in Go? When to use which?

Hello everyone! I've just started learning Go and noticed that for console output you can use both `fmt.Println()` and just `println()`. For example, both of these options work:\n\n```go\npackage main\n\nfunc main() {\n fmt.Println("Hello, world!")\n println("Hello, world!")\n}\n```\n\nBut I noticed that in most examples and tutorials they use `fmt.Println()`. At the same time, `println()` is also in the standard library (or is it a built-in function?). I'm confused because:\n\n1. When using `fmt.Println()` you need to import the `fmt` package, while `println()` works without importing.\n2. `fmt.Println()` can output complex data types (slices, structs), and `println()` seems to do the same.\n3. But I've heard that `println()` is not exactly "pure" Go, and it's not recommended for use in produ