Programming with Python, Unit 4/Week 6, Day 4


#1

https://www.codecademy.com/programs/ba01b5be17f561acf677b424ad95b982/content-items/17b61323990e8d9a2f569cf7b4353d94/exercises/countx-ii

I’m having issues understanding Question # 4 Count Multi- X in the String Methods Code Challenge. I was struggling with this problem quite a bit and I looked at the solution to see how far off my answer was. Here’s the solution
def count_multi_char_x(word, x):
splits = word.split(x)
return(len(splits)-1)

If you enter this in:
print(count_multi_char_x(“mississippi”, “iss”))

Why does it give you 2?

wouldn’t splits = [‘m’, ‘ippi’] so the length of splits would be 2 - 1 would be 1…so why is this printing 2?


#2

In fact, splits will be, ['m', '', 'ippi'] which has lengh of 3.