{"id":23865,"date":"2021-10-05T20:29:08","date_gmt":"2021-10-05T14:59:08","guid":{"rendered":"https:\/\/python-programs.com\/?p=23865"},"modified":"2021-11-22T18:33:25","modified_gmt":"2021-11-22T13:03:25","slug":"python-program-for-set-add-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-set-add-method\/","title":{"rendered":"Python Program for set add() Method"},"content":{"rendered":"

Python set:<\/strong><\/p>\n

Python set is a list of items that are not ordered. \u2013 Each element in the set must be unique and immutable, and duplicate elements are removed from the sets. Sets are mutable, which means they can be changed after they have been created.<\/p>\n

The elements of the set, unlike other Python sets, do not have an index, which means we cannot access any element of the set directly using the index. To get the list of elements, we can either print them all at once or loop them through the collection.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given set =  {'hello', 'this', 'is'}\r\nValue to be added = 'btechgeeks'<\/pre>\n

Output:<\/strong><\/p>\n

The given set is :\r\n{'this', 'is', 'hello'}\r\nThe set is after a given element to the above given set :\r\n{'this', 'is', 'hello', 'btechgeeks'}<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given set = {'good', 'morning', 'this', 'is', 'btechgeeks'}\r\nValue to be added = 'hello'<\/pre>\n

Output:<\/strong><\/p>\n

The given set is :\r\n{'this', 'btechgeeks', 'good', 'is', 'morning'}\r\nThe set is after a given element to the above given set :\r\n{'this', 'hello', 'btechgeeks', 'good', 'is', 'morning'}<\/pre>\n

Program for Set add() Method in Python<\/h2>\n