{"id":3265,"date":"2022-11-14T20:01:29","date_gmt":"2022-11-14T20:01:29","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3265"},"modified":"2022-11-14T20:01:31","modified_gmt":"2022-11-14T20:01:31","slug":"python-list-count","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-list-count\/","title":{"rendered":"Python List Count"},"content":{"rendered":"<p style=\"text-align: center;\">Python List Count<\/p>\n<p>Now, we are going to discuss the count method. Basically, using this method, we get how many times, some element has occurred in the list. We can simply say that it is going to return the count of an element in the list. Let\u2019s have a look at a simple program, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3276 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON.jpg\" alt=\"\" width=\"1014\" height=\"131\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON.jpg 1014w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON-300x39.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON-768x99.jpg 768w\" sizes=\"auto, (max-width: 1014px) 100vw, 1014px\" \/><\/p>\n<p>As you can see in the above program, we have a simple list, and then we are using the count method on the list. We are trying to count how many times 12 has occurred in the list, and the clear output is 3. you can try executing the program and observing the output as well.<\/p>\n<p>Now, Let\u2019s say that we provide such an argument, which is not at all present in the list, and in such a situation, we get the return value as 0. Let\u2019s have a look at this as well &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3277 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON-1.jpg\" alt=\"\" width=\"891\" height=\"127\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON-1.jpg 891w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON-1-300x43.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-count-METHOD-IN-PYTHON-1-768x109.jpg 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><\/p>\n<p>As you can see, in the count method, we are providing a value, which is not at all present in the list, and the return value from the count method that we are going to get, is simply 0. You can try observing the output of this program as well. We can use the count method in our program, as and when required.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python List Count Now, we are going to discuss the count method. Basically, using this method, we get how many times, some element has occurred in the list. We can simply say that it is going to return the count of an element in the list. Let\u2019s have a look at a simple program, which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3265","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3265"}],"version-history":[{"count":3,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3265\/revisions"}],"predecessor-version":[{"id":4079,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3265\/revisions\/4079"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}