Composite Type: Set and Strings Types

Learn about the set and strings types.

Composite types

Sometimes, we have other reasons for storing unique values. We might want to represent what in mathematics is known as a finite set. For that, we have the set type.

Set and strings types

The set type

A set is a composite type that stores unique values without any order. Because this type is unordered, we can’t retrieve items from it with an index. This is usually not a problem because this type is often used to test for membership. You might, for example, have two sets with some values in them and would like to know which values occur in both sets. Let’s see how we might create these two sets and then print the values that occur in both:

Get hands-on with 1200+ tech skills courses.