Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




add( ) FUNCTION


The 'add( )' Function is used to add an element to the Set.


Example :


x = {"Mohan", "Kriti", "Salim"}
x.add("Nikhil")
print(x) 


Output :



  {'Salim', 'Kriti', 'Nikhil', 'Mohan'}

So, in the above code we have created a 'Set' and initialised to the variable 'x'.


x = {"Mohan", "Kriti", "Salim"}

java_Collections

Next, we have used the 'add( )' Function to add 'Nikhil' to the Set.


x.add("Nikhil")

And 'Nikhil' gets inserted at any location. And that's decided by Python.


java_Collections

And we get the below output,


{'Salim', 'Kriti', 'Nikhil', 'Mohan'}