...

/

Built-in Functions and Set Methods

Built-in Functions and Set Methods

Learn about the usage of some built-in functions and methods of sets.

Using built-in functions on sets

Many built-in functions can be used with sets, as demonstrated below:

Press + to interact
s = {20, 10, 50, 40, 30}
print(len(s)) # return number of items in set s
print(max(s)) # return maximum element in set s
print(min(s)) # return minimum element in set s
print(sorted(s)) # return sorted list (not sorted set)
print(sum(s)) # return sum of all elements in set s
print(any(s)) # return True if any element of s is True
print(all(s)) # return True if all elements of s are True

Note: The ...