adding elements to empty set

0 votes
How to add elements to empty sets in Python?
Jun 13, 2019 by Wajiha
• 1,960 points
623 views

1 answer to this question.

0 votes

Adding elements to a Set:

Elements can be added to a set using two functions, the add() and the update() function.

The add() function adds one element to the existing set as shown below:

Example:

1

2

3

My_Set={1,'s',7.8}

My_Set.add(3)

My_Set

Output: {1, 3, 7.8, ‘s’}

The update() function is used when you want to add more than one element to the existing set.

Example:

1

2

3

My_Set={1,'s',7.8}

My_Set.update([2,4.6,1,'r'])

My_Set

Output:  {1, 2, 4.6, 7.8, ‘r’, ‘s’}

As you can see in the above output, the update() function is taking a list of 4 values and all values except 1 are added to My_Set. This is because 1 is already present in the set and therefore, it cannot be added again. 

answered Jun 13, 2019 by Nisa
• 1,090 points

Related Questions

0 votes
1 answer

Exclusive values from two Sets in Python

There is a direct function available to ...READ MORE

answered Mar 27, 2019 in Python by Mugdha
• 600 points
1,495 views
+1 vote
1 answer

How is set() implemented?

Sets in Python can be created using ...READ MORE

answered Jul 1, 2019 in Python by anonymous
701 views
0 votes
1 answer

Adding elements to a list in python

Use extend() instead: l = [5, 7, 12, ...READ MORE

answered Apr 23, 2018 in Python by Nietzsche's daemon
• 4,260 points
866 views
0 votes
1 answer

How to set data attributes in HTML elements?

Hello @kartik, HTML <div id="mydiv" data-myval="10"></div> JS var a = $('#mydiv').data('myval'); ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,840 points
1,302 views
0 votes
0 answers

How to add elements to an empty array in PHP?

I define an array in PHP : $cart ...READ MORE

Jun 3, 2022 in PHP by Kichu
• 19,040 points
1,012 views
0 votes
1 answer
+4 votes
7 answers

How to set the pipeline name and description for a Jenkinsfile?

You can rename pipeline jobs in jenkins ...READ MORE

answered Oct 11, 2018 in Jenkins by Hannah
• 18,520 points
36,885 views
0 votes
1 answer

How to set a custom install directory for a deb package with fpm

Here's something that you can try... the last ...READ MORE

answered Mar 26, 2018 in Big Data Hadoop by Amrinder
• 140 points
1,741 views
+1 vote
1 answer

Where to set hadoop.tmp.dir? core-site.xml or hdfs-site.xml?

hadoop.tmp.dir (A base for other temporary directories) is ...READ MORE

answered Mar 26, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
9,242 views
+2 votes
2 answers

how to set different provisioning profiles for different targets using Xcode Build

For multiple targets, each task has to ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by ajs3033
• 7,300 points

edited Oct 16, 2018 by Kalgi 5,036 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP