0
Str.startswith ()
beg end index ?? can someone explain it for me? I don't understand why it's false. https://code.sololearn.com/c6M1SE86lj04/?ref=app
11 Answers
+ 7
in your example string the indexes are as follows
0123456789.....
t,h,i,s,i,s, ,a, ,s,t,r,i,n,g
as you can see, index 4 have the letter 'i'
+ 6
beg and end are optional parameters
the default is start at 0
passing beg and end parameters will override default, and will consider the beg index as the begining
+ 5
https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/string_startswith.htm
from the link:
str = "this is string example....wow!!!";
print str.startswith( 'this' ) # True
print str.startswith( 'is', 2, 4 ) # True
print str.startswith( 'this', 2, 4 ) # False
beg/eng is used to set start index and end index for the matched string
+ 5
your code:
str='this is a string'
print (str.startswith('a', 4,6))
letter at index is ' ' (space), that's why False is returned
this code however will return True
str='thisais a string'
print (str.startswith('a', 4,6))
+ 5
maybe this will help
https://code.sololearn.com/ciQfFJ3ddk93/?ref=app
+ 4
no probs :)
+ 1
Ah I see it now.. from the example 'this is string example...' I thought that 'is' was for the verb lol
(so it's like they chose the second word but no..)
thank you !
0
Actually I writed this post because of this website because when I tried:
print str.startswirh( 'string', 4, 6)
I got False..and I don't understand why .
0
It returns False.
and don't we start by 0 ?
0
thanks ..I understand how it works I just don't understand why it's not working in my example :)
0
beg and end are optional parameters
the default is start at 0
passing beg and end parameters will override default, and will consider the beg index as the begining
but in all cases the index of 'a' is 4..right?