Q:

Python String index out of range, difference between s[0] and s[:1]

Hi I am new to Python and  was trying to achieve the function of removing the empty spaces in both ends using. 
trim_1() works perfect , but I got this error  when using the trim_2():
IndexError: string index out of range 

So s[:1] and s[0] are not the same thing?  Why s[:1] works and s[0] does not? 
Anyone could shed some light on this? 
def trim_1(s) :
    while s[:1]  == ' ':
        s= s[1:]
    while s[-1:] == ' ':
        s= s[:-1]
    return s

def trim_2(s) :
    while s[0] == ' ':
        s= s[1:]
    while s[-1] == ' ':
        s= s[:-1]
    return s

A:

This is because Python is tolerant towards out-of-bound indices for slices, while intolerant towards out-of-bound indices for lists/strings themselves, as demonstrated below:
>>> ''[:1] # works even though the string does not have an index 0
''
>>> ''[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: string index out of range

