{"id":75539,"date":"2022-07-12T08:42:31","date_gmt":"2022-07-12T03:12:31","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/"},"modified":"2024-10-15T01:02:19","modified_gmt":"2024-10-14T19:32:19","slug":"set-in-python","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/","title":{"rendered":"Set in Python \u2013 How to Create a Set in Python?"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"#introduction\">Introduction&nbsp;<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#set-in-python\">Set in Python<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#operation-of-set-in-python\">Operation of Set in python<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#how-to-create-an-empty-set-in-python\">How to create an empty set in python?&nbsp;<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#removing-elements-from-a-set\">Removing elements from a set<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#explain-set-methods-in-python\">Explain set methods in python?&nbsp;<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#passing-a-dictionary-to-set()-constructor\">Passing a dictionary to set() constructor<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction\"><strong>Introduction&nbsp;<\/strong><\/h2>\n\n\n\n<p>Python has a built-in set <a href=\"https:\/\/www.mygreatlearning.com\/blog\/types-of-data\/\" target=\"_blank\" rel=\"noreferrer noopener\">data type<\/a> that you can use to store collections of unique items. The set() method is used to create a new set or modify an existing one. In this article, we'll take a look at the different ways you can use the set() method and the different operations you can perform on sets.&nbsp;<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"set-in-python\"><strong>Set in Python<\/strong><\/h2>\n\n\n\n<p>A set, in Python, is an unordered collection of unique items. It's a <a href=\"https:\/\/www.mygreatlearning.com\/blog\/data-structure-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\">data structure<\/a> that's similar to a list, but it has some unique properties. It's a great choice for when you want to store a collection of data that isn't constrained by a particular order or sequence. You can add, remove, and modify elements in a set very easily, and the set will always keep track of the changes.&nbsp;<\/p>\n\n\n\n<p><strong>Creating a Set in Python - Syntax:&nbsp;<\/strong><\/p>\n\n\n\n<p>Let us create a set named setA, The syntax for the same is as shown below: <strong>Syntax:&nbsp;<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsetA = set(&amp;lt;iter&gt;),\u00a0\n<\/pre><\/div>\n\n\n<p>where &lt;iter&gt; : iterable can be anything like list, tuple,etc. List and tuple are the other built-in data structures in python just like settings.&nbsp;<\/p>\n\n\n\n<p>To create a set, you use the set() function. The set() function takes any number of arguments, which are all items that will be added to the set.&nbsp;<\/p>\n\n\n\n<p>In Python, the set() constructor creates a new set object. The set() constructor takes a list of items as an argument and makes a new set that contains only those items.&nbsp;<\/p>\n\n\n\n<p><strong>Example:&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setA = set(&#091;\u2018hello\u2019,\u2019world\u2019]) \nprint(setA) \n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">Output: {'hello', 'world'}\nThe following two examples are worth noting, In Ex1, a set is created using one string \u2018foo\u2019, while in Ex2, notice the output when using the set() function. \nEx1: &gt;&gt;&gt;{'foo'} \nO\/P: {'foo'} \nEx2: &gt;&gt;&gt; set('foo') \nO\/P:{'o', 'f'} \n<\/pre>\n\n\n\n<p>The other way to create a set in python is to define the elements in a set of curly braces: The syntax for the same is shown as follows:&nbsp;<\/p>\n\n\n\n<p><strong>Example:&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setA = {\u201chello\u201d, \u201cworld \u201d} \nprint(setA) \n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">Output: {'hello', 'world'} <\/pre>\n\n\n\n<p>Once you have created a set, you can't add or remove items from it. The only way to change the contents of a set is to create a new set that contains the old set and the new items you want to add.&nbsp;<\/p>\n\n\n\n<p>While sets are incredibly useful for advanced data cleaning, most beginners find it helpful to master simpler structures like lists and basic variables first. Understanding these core building blocks is key to becoming a confident coder. If you are just starting your journey, our Free Python Cours<strong><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" target=\"_blank\" rel=\"noreferrer noopener\">e<\/a><\/strong> offers a gentle, hands-on introduction. It\u2019s the perfect place for total beginners to learn the essential syntax needed to manage any type of data in Python.<\/p>\n\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Free Course<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-title-link\">Python Fundamentals for Beginners Free Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master Python basics, from variables to data structures and control flow. Solve real-time problems and build practical skills using Jupyter Notebook.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>13.5 hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>4.55<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-button\">\n                Enroll for Free\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"operation-of-set-in-python\"><strong>Operation of Set in python<\/strong><\/h2>\n\n\n\n<p>Set operations are important in Python programming because they allow you to quickly and easily manipulate large sets of data. There are several operators that you can use to interact with sets, including:\u00a0<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>union: This function combines two sets into a single set&nbsp;<\/li>\n\n\n\n<li>intersection: This function returns the intersection of two sets&nbsp;<\/li>\n\n\n\n<li>difference: This function returns the difference between two sets&nbsp;<\/li>\n\n\n\n<li>symmetric_difference: This function of the set returns the symmetric difference between two sets&nbsp;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"adding-elements-into-a-set\"><strong>Adding elements into a set<\/strong><\/h3>\n\n\n\n<p>Python has a set() data structure that can be used to store unique values. You can add elements to a set in python by using the add() function.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ex1 : setA = {1,2,3} \nsetA.add(15) \nprint(setA) \n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\"><strong>O\/p: <\/strong>{1,15,2,3}&nbsp;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-create-an-empty-set-in-python\"><strong>How to create an empty set in python?&nbsp;<\/strong><\/h2>\n\n\n\n<p>You can create an empty set in python by using the set() function. One can think an empty set can be created using the curly braces {}, but notice that python interprets empty curly braces as a dictionary. Let us look at this scenario using an example:&nbsp;<\/p>\n\n\n\n<p><strong>Ex1:&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">&gt;&gt;&gt; a ={} \n&gt;&gt;&gt; type(a) \nO\/p: &lt;class 'dict'&gt; \n<\/pre>\n\n\n\n<p><strong>Ex2:&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; a= set() \n&gt;&gt;&gt; type(a) \nO\/p: &lt;class 'set'&gt; \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"removing-elements-from-a-set\"><strong>Removing elements from a set<\/strong><\/h2>\n\n\n\n<p>Now that you know how to create and modify sets, let's take a look at how you can remove elements from a set. There are a few different ways to do this, depending on what you want to achieve. This will delete an element from the set immediately. Alternatively, you can use&nbsp;<\/p>\n\n\n\n<p>the remove() method to remove an element from the set over time. This is useful if you want to keep track of which elements have been removed. There are various ways of removing elements from a set in python.One can also use pop() function, discard() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">discard() function: \nEx1: setA = {\u2018hello\u2019,\u2019world\u2019,\u2019python\u2019} \nsetA.discard(\u2018python\u2019) \nprint(setA) \nO\/p: {'world',\u2019hello\u2019} \nremove() function: \nEx2: setA = {\u2018hello\u2019,\u2019world\u2019,\u2019python\u2019} \nsetA.remove(\u2018python\u2019) \nprint(setA) \nO\/p: {\u2018hello\u2019,'world'} \n\n<\/pre>\n\n\n\n<p>The difference between discard and remove is that discard removes the elements if exist else does nothing, but remove throws an error if the element doesn\u2019t exist.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">pop() function: \nEx3: setA = {\u2018hello\u2019,\u2019world\u2019,\u2019python\u2019} \nsetA.pop() \nprint(setA) \nO\/p: {'world',\u2019hello\u2019} \nclear() function: \nclear() removes all the elements from a given set. \nEx :a = {1,2,3} \na.clear() \nO\/p: set()\n\n<\/pre>\n\n\n\n<p>You've probably heard the terms <a href=\"https:\/\/www.mygreatlearning.com\/blog\/understanding-mutable-and-immutable-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">mutable and immutable<\/a> before, but what do they mean? In Python, a mutable object can be changed, meaning the elements of it can be modified once declared while an immutable meaning the contents of it cannot be changed once declared. Sets are mutable which means the elements can be added or removed (modified) after defining a set.&nbsp;<\/p>\n\n\n\n<p><strong>Disjoint sets:&nbsp;<\/strong><\/p>\n\n\n\n<p>Two sets are said to be disjoint when the two sets have no elements in common. Let us see what method of the set is used to identify if two sets are disjoint or not. a = {4,5,6}&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">b = {1,2,3} \nc = {6} \na.isdisjoint(b) #=&gt; True \na.isdisjoint(c) #=&gt; False \n\n<\/pre>\n\n\n\n<p><strong>Operations of set:&nbsp;<\/strong><\/p>\n\n\n\n<p>To add an element to a set, use the add() method. Similarly, using the remove() method to remove an element from the set, we have seen the various ways of removing an element from the set above. To check if an element is in a set, use the keyword \u201din\u201d.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ex: a = set(&#091;\u2018hello\u2019,\u2019world\u2019]) \nprint(\u2018hello\u2019 in a) \n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\"><strong>O\/p: <\/strong>True&nbsp;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"explain-set-methods-in-python\"><strong>Explain set methods in python?&nbsp;<\/strong><\/h2>\n\n\n\n<p>There are also a few methods you can use to join two or more sets together. The union of two sets is the set of items in either set. The union() method will combine all of the elements from both sets into one set, To union two sets, also the Python operator | can be used. While the intersection() method will only include the elements that are common to both sets, To intersect two sets, the Python operator &amp; can also be used. Finally, the difference() method will create a set containing all of the elements in the first set, minus any elements that are also in the second set.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"set-difference-in-python\"><strong>Set Difference in Python<\/strong><\/h3>\n\n\n\n<p>There are three ways to find the difference between two sets in Python. The first is set difference, which returns the elements in set A that are not in set B. The second is set symmetric difference, which returns the elements in set A that are not in set B, as well as the elements in set B that are not in set A. The third is the Cartesian product, which returns a new set that is the result of pairing every element in set A with every element in set B.&nbsp;<\/p>\n\n\n\n<p><strong>Ex1 :&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">Set Difference: \ns1 = {1,2,3,4,5} \ns2 = {4,5,6,7,8} \ns1.difference(s2) \nO\/p: {1, 2, 3} \nSymmetric difference: \nx= {1,2,4} \ny={2,5,6} \nz = x.symmetric_difference(y) \n\n<strong>O\/p: <\/strong>{1, 4, 5, 6}&nbsp;\n<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"passing-a-dictionary-to-set-constructor\"><strong>Passing a dictionary to set() constructor<\/strong><\/h2>\n\n\n\n<p>You can also use the set constructor to create a new set from a dictionary. When you pass a dictionary to the set constructor, it will create a new set where only the keys in the dictionary are returned&nbsp;<\/p>\n\n\n\n<p><strong>Ex:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">d = {'dog': 1, 'cat':2, 'fish':3} \nset(d) \nO\/p: {'cat', 'dog', 'fish'} \nWe can also zip two sets using the zip() function, but the order cannot be preserved. Look at the example below to get a clear understanding. \nEx: z = zip({1,2,3},{'a','b','c'}) \nlist(z) \nO\/p: [(1, 'c'), (2, 'b'), (3, 'a')] \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion&nbsp;<\/strong><\/h2>\n\n\n\n<p>You've learned about the different ways you can create a set() in python, as well as how to modify it. We hope you find this information helpful and that you're now empowered to create and work with sets in your python programs!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction&nbsp; Python has a built-in set data type that you can use to store collections of unique items. The set() method is used to create a new set or modify an existing one. In this article, we'll take a look at the different ways you can use the set() method and the different operations you [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":74778,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[],"class_list":["post-75539","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Set in Python \u2013 How to Create a Set in Python?<\/title>\n<meta name=\"description\" content=\"Set in Python- In this guide you&#039;ll learn everything about Python sets; and all operations performed on sets in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set in Python \u2013 How to Create a Set in Python?\" \/>\n<meta property=\"og:description\" content=\"Set in Python- In this guide you&#039;ll learn everything about Python sets; and all operations performed on sets in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-12T03:12:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-14T19:32:19+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"853\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Set in Python \u2013 How to Create a Set in Python?\",\"datePublished\":\"2022-07-12T03:12:31+00:00\",\"dateModified\":\"2024-10-14T19:32:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/\"},\"wordCount\":1243,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/coding-924920_1280.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/\",\"name\":\"Set in Python \u2013 How to Create a Set in Python?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/coding-924920_1280.jpg\",\"datePublished\":\"2022-07-12T03:12:31+00:00\",\"dateModified\":\"2024-10-14T19:32:19+00:00\",\"description\":\"Set in Python- In this guide you'll learn everything about Python sets; and all operations performed on sets in Python.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/coding-924920_1280.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/coding-924920_1280.jpg\",\"width\":1280,\"height\":853,\"caption\":\"Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/set-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Set in Python \u2013 How to Create a Set in Python?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Set in Python \u2013 How to Create a Set in Python?","description":"Set in Python- In this guide you'll learn everything about Python sets; and all operations performed on sets in Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Set in Python \u2013 How to Create a Set in Python?","og_description":"Set in Python- In this guide you'll learn everything about Python sets; and all operations performed on sets in Python.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2022-07-12T03:12:31+00:00","article_modified_time":"2024-10-14T19:32:19+00:00","og_image":[{"width":1280,"height":853,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Set in Python \u2013 How to Create a Set in Python?","datePublished":"2022-07-12T03:12:31+00:00","dateModified":"2024-10-14T19:32:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/"},"wordCount":1243,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/","url":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/","name":"Set in Python \u2013 How to Create a Set in Python?","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg","datePublished":"2022-07-12T03:12:31+00:00","dateModified":"2024-10-14T19:32:19+00:00","description":"Set in Python- In this guide you'll learn everything about Python sets; and all operations performed on sets in Python.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg","width":1280,"height":853,"caption":"Python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Set in Python \u2013 How to Create a Set in Python?"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg",1280,853,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-1024x682.jpg",1024,682,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg",1280,853,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280.jpg",1280,853,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-640x853.jpg",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/coding-924920_1280-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Introduction&nbsp; Python has a built-in set data type that you can use to store collections of unique items. The set() method is used to create a new set or modify an existing one. In this article, we'll take a look at the different ways you can use the set() method and the different operations you&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/75539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=75539"}],"version-history":[{"count":10,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/75539\/revisions"}],"predecessor-version":[{"id":110857,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/75539\/revisions\/110857"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/74778"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=75539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=75539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=75539"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=75539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}