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

16th May 2017, 7:36 PM
Alluka Smile
Alluka Smile - avatar
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'
16th May 2017, 8:20 PM
Burey
Burey - avatar
+ 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
16th May 2017, 8:09 PM
Burey
Burey - avatar
+ 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
16th May 2017, 7:51 PM
Burey
Burey - avatar
+ 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))
16th May 2017, 7:58 PM
Burey
Burey - avatar
16th May 2017, 8:13 PM
Burey
Burey - avatar
+ 4
no probs :)
16th May 2017, 8:42 PM
Burey
Burey - avatar
+ 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 !
16th May 2017, 8:28 PM
Alluka Smile
Alluka Smile - avatar
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 .
16th May 2017, 7:54 PM
Alluka Smile
Alluka Smile - avatar
0
It returns False. and don't we start by 0 ?
16th May 2017, 8:03 PM
Alluka Smile
Alluka Smile - avatar
0
thanks ..I understand how it works I just don't understand why it's not working in my example :)
16th May 2017, 8:14 PM
Alluka Smile
Alluka Smile - avatar
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?
16th May 2017, 8:15 PM
Alluka Smile
Alluka Smile - avatar