Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialryan smith
687 PointsWhy doesn't alpha.index('cd') give the value of 2 AND 3
At 2:30
alpha = 'abcdef' alpha.index('cd')
You get the value of 2. Why doesn't it give the value of 2 and 3 especially since he stated you could do index with groups, but it only states one value?
What if I want both occurrences (if it's just giving me the first occurrence). Why does it even give the first one and not both, is there a important disguised reason?
1 Answer
Sumit Roy
2,905 Pointshere index is returning the first occurrence of the substring 'cd' in the string 'abcde'
ryan smith
687 Pointsryan smith
687 PointsThanks. What if i want both occurences?
Sumit Roy
2,905 PointsSumit Roy
2,905 PointsYou are asking for the occurence of substring 'cd' and there is only one occurence of that. If you want index of both 'c' and 'd' you have to do two index call. 'abcd'.index('c') and 'abcd'.index('d')