{"id":20625,"date":"2021-10-06T09:09:37","date_gmt":"2021-10-06T03:39:37","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=20625"},"modified":"2022-09-06T19:26:55","modified_gmt":"2022-09-06T13:56:55","slug":"python-set-size-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/","title":{"rendered":"Python set size | Example code"},"content":{"rendered":"\n<p>Use the <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-string-length-len-function-and-other-ways\/\">len() method <\/a>to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the number of items in the set.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python set size example code<\/strong><\/h2>\n\n\n\n<p>Python program to find the length of a set.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_set = {'A', 'B', 'C', 'D'}\n\nprint(len(my_set))\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"222\" height=\"121\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg?resize=222%2C121&#038;ssl=1\" alt=\"Python set size\" class=\"wp-image-20675\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How to find the length of a set in Python<\/strong><\/h3>\n\n\n\n<p><strong>Answer<\/strong>: You can find the length of the Python Set object using the len() function. Tuple as an element count only 1 value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_set = set()\n\n# Adding element and tuple to the Set\nmy_set.add(1)\nmy_set.add(2)\nmy_set.add((4, 5))\n\nprint(my_set)\nprint(len(my_set))\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n\n<p>{(4, 5), 1, 2}<br>3<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts or suggestions on this Python set tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the number of items in the set. Python set size example code Python program to find the length of a set. Output: How to find the length of&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Python set size | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[224],"post_series":[],"class_list":["post-20625","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-set"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python set size | Example code<\/title>\n<meta name=\"description\" content=\"Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python set size | Example code\" \/>\n<meta property=\"og:description\" content=\"Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-06T03:39:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-06T13:56:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/\",\"name\":\"Python set size | Example code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg\",\"datePublished\":\"2021-10-06T03:39:37+00:00\",\"dateModified\":\"2022-09-06T13:56:55+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg?fit=222%2C121&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg?fit=222%2C121&ssl=1\",\"width\":222,\"height\":121},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python set size | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python set size | Example code","description":"Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the","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:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Python set size | Example code","og_description":"Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the","og_url":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-10-06T03:39:37+00:00","article_modified_time":"2022-09-06T13:56:55+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/","name":"Python set size | Example code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg","datePublished":"2021-10-06T03:39:37+00:00","dateModified":"2022-09-06T13:56:55+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use the len() method to Get the size of a Set in Python. Call len() built-in function and pass the set object as an argument. It returns the","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg?fit=222%2C121&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-size.jpg?fit=222%2C121&ssl=1","width":222,"height":121},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-set-size-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Python set size | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":20552,"url":"https:\/\/tutorial.eyehunts.com\/python\/is-set-mutable-in-python\/","url_meta":{"origin":20625,"position":0},"title":"Is set mutable in Python?","author":"Rohit","date":"October 4, 2021","format":false,"excerpt":"Yes, Python sets are mutable because the set itself may be modified, but the elements contained in the set must be of an immutable type. Example code to check set mutable in Python Simple example code. However, since Python sets are unordered, indexing doesn't matter. We cannot access or change\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Is set mutable in Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Is-set-mutable-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20576,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-set-to-list-conversion-example-code\/","url_meta":{"origin":20625,"position":1},"title":"Python set to list | Conversion example code","author":"Rohit","date":"October 5, 2021","format":false,"excerpt":"You can use the list() Function or manual Iteration to convert the set into the list in Python. Python set to list example code Simple example code. Using list() Function It is a built-in method that takes an iterable as an argument and converts that into a List type object.\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python set to list","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-to-list.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20621,"url":"https:\/\/tutorial.eyehunts.com\/python\/append-to-set-python-example-code\/","url_meta":{"origin":20625,"position":2},"title":"Append to set Python | Example code","author":"Rohit","date":"October 7, 2021","format":false,"excerpt":"Use The set add() method to append a given element into a set in Python. The new element will add only if the element is not present in the current set. Use the update() method to add iterable objects into sets. Note: The add() method use only add one item\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Append to set Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Append-to-set-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20623,"url":"https:\/\/tutorial.eyehunts.com\/python\/how-to-create-a-set-in-python-example-code\/","url_meta":{"origin":20625,"position":3},"title":"How to create a set in Python | Example code","author":"Rohit","date":"October 7, 2021","format":false,"excerpt":"You can create a set by using curly braces {} in Python. Just create a data type and assign the value using placing all the items (elements) inside curly braces {} and separated by a comma for multiple values. Declare set my_set = {\"e1\", \"e2\", \"e2\"} empty_set = set() Python\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"How to create a set in Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/How-to-create-a-set-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20582,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-set-add-method-example-code\/","url_meta":{"origin":20625,"position":4},"title":"Python set add method | Example code","author":"Rohit","date":"October 8, 2021","format":false,"excerpt":"Using add method you can add a given element to an existing set. If a given element already presents in the list then it will not add because the set has unique values. set.add(elem) However, you can't change sets after created but you can add new items. Python set add\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python set add method","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-set-add-method.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20572,"url":"https:\/\/tutorial.eyehunts.com\/python\/list-to-set-python-conversion-example-code\/","url_meta":{"origin":20625,"position":5},"title":"List to set Python | Conversion example code","author":"Rohit","date":"October 7, 2021","format":false,"excerpt":"Use the set() function to convert a list to a set in Python. Sets are not allowed duplicate elements (values), if you convert a list to a set then all duplicates will be removed in the new set. set(iterable) Example List to set Python Simple example code using a list\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"List to set Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/List-to-set-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/20625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=20625"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/20625\/revisions"}],"predecessor-version":[{"id":32678,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/20625\/revisions\/32678"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=20625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=20625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=20625"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=20625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}