Python set() Function24 Apr 2025 | 1 min read In 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 |
Function function is used to delete an attribute from a class. It takes two parameters first is an object of the class and second is an attribute which we want to delete. After deleting the attribute, it no longer available in the class and throws...
1 min read
Function The python memoryview() function returns a memoryview object of the given argument. Before we come to the memoryview, we have to understand about Python's Buffer Protocol. Buffer Protocol provides a way to access internal data of an object. This internal data is a memory array or a...
2 min read
Function function is used to get input from the user. It prompts for the user input and reads a line. After reading data, it converts it into a string and returns that. It throws an error EOFError if EOF is read. Signature input ([prompt]) Parameters prompt: It is a...
1 min read
Function function is used to create a tuple object. Signature tuple(iterable) Parameters Iterable: It is a sequence, collection, or an iterator object. Return It returns a tuple. Function Example 1 The below example creates tuple using tuple(). t1 = tuple() print('t1=', t1) # creating a tuple from a list t2 = tuple([1, 6, 9]) print('t2=',...
1 min read
Function function is used to check whether the given object is an instance of that class. If the object belongs to the class, it returns True. Otherwise returns False. It also returns true if the class is a subclass. The isinstance() function takes two arguments object...
3 min read
Function function returns the __dict__ attribute of the given object. Signature vars(object) Parameters object (optional): It is an object and can be a module, class, instance, or any other object having __dict__ attribute. Return It returns the __dict__ attribute of the given object. If any object fails to match the...
1 min read
Function Python is a flexible programming language with a vast library of functions that can make coding a lot more straightforward. Quite possibly of the most remarkable and frequently used function in Python is the eval() function. In this article, we will examine the eval() function...
3 min read
Function The python abs() function is used to return absolute value of a number. It takes only one argument, a number whose absolute value is to be returned. The argument can be an integer and floating point number. If the argument is a complex number, then,...
1 min read
Function The python object() returns an empty object. It is a base for all the classes and holds the built in properties and methods which are default for all the classes. Signature object() Return It returns an empty object. Function Example 1 The below example shows the working of object(). python =...
1 min read
Function function prints the given object on the screen or other standard output devices. Signature print(object(s), sep=separator, end=end, file=file, flush=flush) Parameters object(s): It is an object to be printed. The Symbol * indicates that there may be more than one object. sep='separator' (optional): The objects are separated by sep. The...
2 min read
We request you to subscribe our newsletter for upcoming updates.

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