0
python
Can someone please explain me the below code str1 = "my isname isisis jameis isis bond"; sub = "is"; print(str1.count(sub,4)) # Output:- 6 #----------------------------------------------------------------- str1 = "my isname isisis jameis isis bond"; sub = "is"; print(str1.count(sub,2)) # Output:- 7
3 Answers
+ 2
Amol Bhandekar
count(string, start_position); #start_position - index
In first case start position is 4 so it will be count after the 5th character
In second case start position is 2 so it will be count after the 3rd character
+ 3
Quoted from
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_count.asp
"The count() method returns the number of times a
specified value appears in the string.
Syntax:
string.count(value, start, end)"
The method allows optional arguments - a range of indices which specifies from which index and to which index should the argument be counted.
If <start> index is omitted, the counting starts from 0th character.
If <end> index is omitted, the counting runs to the end of the string - minus length of <value>
+ 1
Thank AJ Understood
means here we used indexing...