Let me ask you a question, if someone in the HR department, as a result of mistake, has repeatedly registered some names, how can we quickly solve this problem? Shall we use a double-loop for comparison and then delete the repeated item, or sort them and then delete the repeated item? In fact, both are not needed in Python. In Python, there is a special data structure "set". It does not appear in many other programming languages. But it is very convenient when used in some special applications. Let's look at how this seemingly complex question is handled with set. Here, we see the repetitive names. Its solution is quite simple. Use the "set()" function to process the list. In the end, we see the output result is a set not containing repetitive objects. Very convenient, right? A set is indeed an unordered combination of non-repetitive elements. It can be divided into two types, one is the mutable set, "set", and the other is the immutable set, "frozenset". Let's see how a set is created and how it is used. We may use the "set()" function and the "frozenset()" function to create, respectively the mutable set and the frozen set. For example, we first create a mutable set. Use the "set()" function. Here, as we know, all elements in the set are non-repetitive. As we see, the "l" in "hello" is repeated. We only see one "l" in the result. Then, let's create an immutable set with the frozen"set()" function. Let's check their types. They are "set" and "frozenset", respectively. As for sets, we may also compare them with some symbols. For example, we have defined two sets "aSet" and "bSet", we may use "in" or "not in" operators for belonging/not belonging to to determine whether some objects are in the set. For instance, let's see whether 'u' is inside the set "aSet". We see there is an object of "u" in "aSet" so the result of operation is "True". We may also use "==" or "!=" the two operators, to judge whether the two sets are identical. In fact, it is to see whether their members are identical. We see here, some members are different. Members like "r" and "i", for example, do not exist in "bSet". So, the result is "False". Next, look at this "<". What does this "<" mean? It is different from the sign of less than for strings. For strings, you might compare two. For comparison with a smaller one, i.e., when the first one is smaller, the result will be "True". Here, we actually see "<", "<=", ">", ">=". What do they represent, respectively? It is a relation of inclusion like properly including or ordinary including. Here, we see this "<", meaning whether the left is a proper subset of the right. And, this means whether this is one of its subsets. This means whether this is its proper superset. And this, whether this is its superset. So, as we see, "aSet" is not a proper subset of "bSet". So, the result is "False". Next, look at this form, "sun" consists of "s", "u" and "n" those three characters. So, it is indeed a proper subset of "aSet". So, the result is "True". The charm of set, to a large extent, lies in that the set can be applied with relational operations. Intersection, union and difference, say, are the most common relational operations of sets. Besides, how about this symbol? What does it mean? Yes. symmetry and variance. Another term is "exclusive or". It also appears frequently in sets. Let's look at several examples to feel the actual effect of the several relational operations. For example, there are two sets "aSet" and "bSet" like those before. As for this symbol, we know it's intersection. That is to say, it is to find the same members from two sets. Here we see the same members include "s", "u", "n" and "e". So, we see the result as 'u', 's', 'e', 'n'. This symbol means union. What does "union" mean? It is to combine members in two sets. So, the final result is like this. Then, let's look at the meaning of "difference". Let's think about it, based on the operational result "i" and "r", "i" and "r" are at this position. We might have noticed that the two members appear in aSet, but not in bSet. So, that's the meaning of difference. "Difference" means that it belongs to the set "aSet", but not to "bSet". In Python, "difference" is sometimes referred to as "difference complement". Let's look at another operator, i.e., symmetric difference. We see its result of operation is 'i', 'r', 't'. It seems similar to the difference mentioned just now. But, it has one more member 't' from bSet. Have you noticed where the result 'i', 'r', 't' come from? They all belong to the sets "aSet" and "bSet" but they are only inside one set, i.e., not simultaneously in both sets. So, are the 'i' 'r' 't' we see here inside "aSet" and "bSet"? But they are only in a particular set. So, that's the result of symmetric difference. Moreover, those relational operators can be combined. For example, we may write them into these forms "union equal" or "or equal" or "difference equal" or this form "symmetric difference equal". So, we may use this composite operator like this to conduct the corresponding difference processing. For example, "aSet" is removed from such a set 's', 'u' and 'n', so the final result is 'r', 'i' and 'e' such an operational result. This is the relational operation of sets. Similarly, sets also have some built-in functions. The built-in functions in sets are divided into two types. One is for all sets, i.e., for both mutable sets and frozen sets. How about the other type? You can have a guess first. Is this type for mutable sets or frozen sets? Should it be for mutable sets? They include something like deletion and updating. Let's first look at some functions for all sets. For example, we still use two sets "aSet" and "bSet", we can resort to this function or, from its name, we can see it means whether this is its subset. That is to say, is aSet a subset of bSet. So, the result is False. Let's look at this form, "difference()", which actually means to find the difference complement. Sure, some other functions are also available. We may use them too like "copy()" for copying a set. As for an immutable set, we also mentioned it just now. For example, we may update it in certain ways. An update may be a normal update or intersection update or difference complement update. It's also OK to use the "add()" function or "remove()" and "pop()" etc. It allows an action to members of the set. For example, we see this simple "add()" to add "i" into the set. In this set, we see a new member – the exclamation mark. Then, you may delete it, with "remove()". We may also update the set "aSet". For example, we may add the 4 members of this object "yeah". 'Y','e', 'a' and 'h'. The result is changed into this form. We may also clear a set. It is like this after clearing. Thus, sets are actually rather simple. We should grasp the most fundamental characteristic of sets, i.e., all members inside are different. In addition, there are some relational operations for sets, with which we should also be familiar. Some functions may also be directly used. Of course, different individuals may feel differently. For example, many would feel some functions here like functions related to relational operations, in particular, may not be as simple as some operators. That's also OK.