Python set() FunctionIn python, a set is a built-in class, and this function is a constructor of this class. It is used to create a new set using elements passed during the call. It takes iterable as an argument and returns a new set object. The constructor syntax is given below. SignatureParametersiterable: a collection of immutable elements. ReturnIt returns a new set. Let's see some examples of set() function to understand it's functionality. Python set() Function Example 1A simple example to create a set of using iterable elements. Output: set() {'1', '2'} {'a', 'n', 'v', 't', 'j', 'p', 'i', 'o'} Python set() Function Example 2Output: {'15', '13', '12'} {'n', 'v', 'a', 'j', 'p', 't', 'o', 'i'} {1, 2, 3} Python set() Function Example 3Here, we are creating a set of filtered elements. The geteven function returns even values. Output: {8, 2, 4, 6} Next TopicPython Functions |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India