Built-in Functions and Set Methods
Learn about the usage of some built-in functions and methods of sets.
We'll cover the following...
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 sprint(max(s)) # return maximum element in set sprint(min(s)) # return minimum element in set sprint(sorted(s)) # return sorted list (not sorted set)print(sum(s)) # return sum of all elements in set sprint(any(s)) # return True if any element of s is Trueprint(all(s)) # return True if all elements of s are True
Note: The ...