How do you check if a value is one of multiple values?
💡 Model Answer
To check if a value is one of multiple values, most languages provide an 'in' operator or a similar construct. In Python, you can write: if value in ['silver', 'gold']: ... . In JavaScript, use the includes() method: if (['silver', 'gold'].includes(value)) { ... }. In SQL, you can use the IN clause: SELECT * FROM table WHERE status IN ('silver', 'gold');. These constructs evaluate to true if the value matches any element in the collection. They are concise and efficient, and they avoid writing multiple OR conditions. If the collection is large, consider using a set or hash for O(1) lookup in languages that support it. In Java, you can use a Set: Set<String> valid = new HashSet<>(Arrays.asList("silver", "gold")); if (valid.contains(value)) { ... }.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500