adding elements to empty set

0 votes
How to add elements to empty sets in Python?
Jun 13, 2019 by Wajiha
• 1,950 points
103 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
126 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
75 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
106 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 4 in JQuery by Niroj
• 68,560 points
24 views
+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,420 points
19,050 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
311 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
• 10,950 points
4,257 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 26, 2018 in DevOps & Agile by ajs3033
• 7,280 points

edited Oct 16, 2018 by Kalgi 1,598 views
+4 votes
2 answers

Amazon S3 Permission problem - How to set permissions for all files at once?

This can be done by setting the ...READ MORE

answered Mar 27, 2018 in Cloud Computing by brat_1
• 7,170 points
344 views
0 votes
1 answer