{"id":4723,"date":"2017-12-07T00:36:14","date_gmt":"2017-12-06T19:06:14","guid":{"rendered":"https:\/\/www.java2blog.com\/?p=4723"},"modified":"2023-11-22T01:16:30","modified_gmt":"2023-11-21T19:46:30","slug":"python-list-count","status":"publish","type":"post","link":"https:\/\/java2blog.com\/python-list-count\/","title":{"rendered":"Python List count()"},"content":{"rendered":"<p>In this tutorial, we will see about <a href=\"https:\/\/www.java2blog.com\/python-list-tutorial\/\" target=\"_blank\" rel=\"noopener\">Python List<\/a>&#8216;s count method.Python List count method is used to count a number of instances of the element in the list.<\/p>\n<h2><span style=\"color: #f89820;\">Python List count example<\/span><\/h2>\n<p>You can simply use count method to find number of occurrences of element in the list.<br \/>\nLet&#8217;s understand this with the help of simple example.<\/p>\n<pre code=\"python\">\nlist1=[1,2,3,2,3,2,2,3,4,4,1,1,2]\nprint(\"Count of 1 in the list1:\",list1.count(1))\nprint(\"Count of 2 in the list1:\",list1.count(2))\nprint(\"Count of 3 in the list1:\",list1.count(3))\nprint(\"Count of 4 in the list1:\",list1.count(4))\n\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"content-box-green\">\nCount of 1 in the list1: 3<br \/>\nCount of 2 in the list1: 5<br \/>\nCount of 3 in the list1: 3<br \/>\nCount of 4 in the list1: 2\n<\/div>\n<p>You can also find count of set or tuple too.Let&#8217;s see with the help of example.<\/p>\n<pre code=\"python\">\nlist1=['one',{1,2},'three',{1,2}]\nprint('Count of set {1,2}:',list1.count({1,2}))\n\nlist2=['one',(3,4),'three',(3,4),(3,4)]\nprint('Count of tuple (3,4) :',list2.count((3,4)))\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"content-box-green\">\nCount of set {1,2}: 2<br \/>\nCount of tuple (3,4) : 3\n<\/div>\n<p>That&#8217;s all about Python List count method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will see about Python List&#8216;s count method.Python List count method is used to count a number of instances of the element in the list. Python List count example You can simply use count method to find number of occurrences of element in the list. Let&#8217;s understand this with the help of [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false},"categories":[146,145],"tags":[],"_links":{"self":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/4723"}],"collection":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/comments?post=4723"}],"version-history":[{"count":1,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/4723\/revisions"}],"predecessor-version":[{"id":25583,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/4723\/revisions\/25583"}],"wp:attachment":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/media?parent=4723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/categories?post=4723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/tags?post=4723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}