Â In this section we discuss and learn about the length of set in python. First we discuss the set. So what is set? Set is the one of the types of data type programmer store their vaue like string, integers, boolen value, float, decimal.Â

The main important point is these the python programming language developer does not fix the length ofÂ set in python.

The programmer is only see the how many length of variable in set. If the programmer set the high length than their is crash the RAm of computer their is use the yeild and next method to save the computer Ram.

Python set length |

Computer Ram is low than thir is problem with set the high length. Beginner programmer is confused the length of set. When beginner programmer is make program using set data types. Than they save data in high amount and their Ram is crash so they confused the maximum length of set.

Now we will see the example with writing code and describe the code with one by one. No confuse in any line of code.

```
length_of_set= {1,2,3,4,5,6,7,"Rahul","meta","hari","set length python"}
print(length_of_set)
print(type(length_of_set))
print(len(length_of_set))
```

First we make the set with name length of set. print the set with type and len. Len is the python built in function with the help of len. Programmer find the length of any data types value.

INOUTPUT

```
{1, 2, 3, 4, 5, 6, 7, 'set length python', 'meta', 'Rahul', 'hari'}
class 'set'
11
```

Now we see the advance method to see the set of length with the helps of oops condition.

```
class set_of_length():#creating class
def __init__(self):#init constructor
self.set_length = {1,2,3,4,5,6,7,8,"om","shivaya","vishnu_avatar","shivling"}#instance variable
def print_length_of_set(self):
print(f"Inside the swt variable is {self.set_length}")
print(f"The length of this set is {len(self.set_length)}")
def __len__(self):
print(f"using __len__ total length of set is {self.set_length.__len__()}")
how_many_length_of_set = set_of_length()
how_many_length_of_set.print_length_of_set()
how_many_length_of_set.__len__()
```

First we make the the oops class with name set of length creating the constructor make instance variable in and the data types is set. making 2 function to print set and length of set. First we use len function to find the length of set.

Inside the second function we use the __len__ function. Mainly it is use in oops concept to find the length of set or data type. __len__ is also known as a dunder method. At last printing the set and set len and __len__.Â

INOUTPUT

```
Inside the swt variable is {1, 2, 3, 4, 5, 6, 7, 8, 'shivling', 'vishnu_avatar', 'shivaya', 'om'}
The length of this set is 12
using __len__ total length of set is 12
```

## 0 Comments

Don't comment a spam message