Avatar ·

Is there an "if x in" construct in Go for checking membership in a list, like in Python?

Hi everyone! I just started learning Go after Python and ran into a problem. In Python, I'm used to writing like this:\n\n```python\nfruits = ["apple", "banana", "cherry"]\nif "apple" in fruits:\n print("Found!")\n```\n\nThis is very convenient — checking if an element is in a list in one line. Now I'm trying to do the same in Go:\n\n```go\npackage main\n\nimport "fmt"\n\nfunc main() {\n fruits := []string{"apple", "banana", "cherry"}\n // How to check if "apple" is in the slice?\n // if "apple" in fruits { // Compilation error\n // fmt.Println("Found!")\n // }\n}\n```\n\nI understand that Go is a strongly typed language, but is there really no built-in way? I tried looking in the documentation but didn't find anything similar. Maybe there is some syntax with range or ma