Functions¶
Function definition, multiple return values, variadic, lambda, closures, and decorators.
def¶
Multiple Return Values¶
*args¶
**kwargs¶
// Go has no keyword arguments — use an options struct instead
type ConnectOpts struct {
Port int
Timeout int
SSL bool
}
func connect(host string, opts ConnectOpts) {
if opts.Port == 0 { opts.Port = 5432 }
if opts.Timeout == 0 { opts.Timeout = 30 }
// ...
}
connect("localhost", ConnectOpts{Port: 3306, SSL: false})
Zero value trap with defaults
A struct field's zero value (0, false, "") is indistinguishable from "not set".
If you need to tell them apart, use pointer fields (*int) or a separate bool flag.