Avatar ·

How to check if a map contains a key in Go?

Hello everyone! I just started learning Go and I have a problem with maps. Let's say I create a map that stores users by their ID: ```go users := map[int]string{ 1: "Alice", 2: "Bob", } ``` I need to check if a user with ID, for example, 3 exists. I tried doing this: ```go if users[3] != "" { fmt.Println("User found") } else { fmt.Println("User not found") } ``` But this seems wrong because if the value is empty (for example, a user has an empty name), the check will break. Additionally, I heard that in Go, when accessing a non-existent key, it returns the zero value for the value type. For strings it's an empty string, for numbers it's 0, for booleans it's false. But how then to distinguish the absence of a key from