Home > Article > Backend Development > How to input a set in python
The set() function creates an unordered set of non-repeating elements, which can perform relationship testing, delete duplicate data, and calculate intersection, difference, union, etc.
set Syntax:
class set([iterable])
Parameter description:
iterable -- iterable object object;
Return value:
Return the new collection object.
The following examples show how to use set:
>>>x = set('runoob') >>> y = set('google') >>> x, y (set(['b', 'r', 'u', 'o', 'n']), set(['e', 'o', 'g', 'l'])) # 重复的被删除 >>> x & y # 交集 set(['o']) >>> x | y # 并集 set(['b', 'e', 'g', 'l', 'o', 'n', 'r', 'u']) >>> x - y # 差集 set(['r', 'b', 'u', 'n'])
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to input a set in python. For more information, please follow other related articles on the PHP Chinese website!