The count() method in Python is used to count the number of times a certain character appears in a string. Optional parameters are the start and end positions of the string search. count() method syntax:
str.count(sub, start= 0,end=len(string)); the size() function is mainly used to count the number of matrix elements, or a certain dimension of the matrix function of the number of elements.
count()
##Parameters
sub -- The search substring start -- The position in the string where the search begins. The default is the first character, and the index value of the first character is 0. end – The position in the string where the search ends. The first character in the string has index 0. Defaults to the last position of the string.Return value
This method returns the number of times the substring appears in the string.Examples
The following examples show examples of the count() method:#!/usr/bin/python str = "this is string example....wow!!!"; sub = "i"; print "str.count(sub, 4, 40) : ", str.count(sub, 4, 40) sub = "wow"; print "str.count(sub) : ", str.count(sub)
str.count(sub, 4, 40) : 2 str.count(sub, 4, 40) : 1
[1,1,1,2].count(1), the return value is 3
'asddf'.count('d'), the return value is 2
Python Video Tutorial"
size()
Parameters
numpy.size(a, axis=None)
>>> a = np.array([[1,2,3],[4,5,6]]) >>> np.size(a) 6 >>> np.size(a,1) 3 >>> np.size(a,0) 2
a = np.array([[1,2,3],[4,5,6]])
np.size(a), the return value is 6.
np.size(a,1), the return value is 3.
The above is the detailed content of The difference between size and count in python. For more information, please follow other related articles on the PHP Chinese website!