Python List count() MethodPython count() method returns the number of times element appears in the list. If the element is not present in the list, it returns 0. The examples and syntax is described below. SignatureParametersx: element to be counted. ReturnIt returns number of times x occurred in the list. Let's see some examples of count() method to understand it's functionality. Python List count() Method Example 1It is a simple example to understand how a count method works. Output: count of p : 2 Python List count() Method Example 2If the passed value is not present in the list, the method returns 0. See the example below. Output: count of b : 0 Python List count() Method Example 3Python count() method can also be used to check whether an element is duplicate in the list or not. The below example checks the duplicacy of the element in the list. Output: value is duplicate count of p : 2
Next TopicPython Lists
|