Avatar ·

Ternary operator equivalent in Go: how to write a conditional expression in one line?

Hello everyone! I just started learning Go after several years working with Python and JavaScript. In these languages, I often used the ternary operator for compact conditional assignments, for example: ```python status = "active" if user.is_logged_in else "inactive" ``` In Go, I'm trying to do something similar: ```go package main import "fmt" func main() { age := 20 status := age >= 18 ? "adult" : "child" fmt.Println(status) } ``` But the compiler gives an error. I understand that Go doesn't have a ternary operator, but how can I elegantly write a simple conditional assignment without bloating the code? I tried using if-else, but it takes 4-5 lines instead of one. Is there an idiomatic way to do this concisely? Maybe there's some built-in mechanism or a commonly accepted