adding elements to empty set

0 votes
How to add elements to empty sets in Python?
Jun 13 by Wajiha
• 1,840 points
17 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 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 in Python by Mugdha
• 580 points
39 views
+1 vote
1 answer

How is set() implemented?

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

answered Jul 1 in Python by anonymous
19 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
34 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
• 14,090 points
6,194 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
65 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,510 points
1,673 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 589 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,080 points
43 views
0 votes
1 answer
0 votes
1 answer

How do I set the zoom level of Internet Explorer to 100% when using python _winreg

My qustion is, by default for testing ...READ MORE

answered Mar 30, 2018 in Selenium by nsv999
• 5,070 points
743 views