slice operation of consequence in python
the slice operation consequence is easy.
the prototype of the function is str[start:end:step] .
then let's see the following examples:
>>>str1='abcde'
>>>str1[1:3]
'bc'
>>>str1[:] #default start is 0 and default end is (len(str)-1)
'abcde'
>>>str1[1:4:1]
'bcd'
>>>str1[0:4:2]
'ace'
>>>str1[-4]
'b'
>>>str1[-4:-1]
'bcd'
>>>str1[-4:-1:1]
'bcd'
>>>str1[-4:-1:-1]
'dcb'
>>>str1[::2] #default start is 0 and default end is (len(str)-1)
'aec'
slice operation of consequence in python
the slice operation consequence is easy.
the prototype of the function is str[start:end:step] .
then let's see the following examples:
>>>str1='abcde'
>>>str1[1:3]
'bc'
>>>str1[:] #default start is 0 and default end is (len(str)-1)
'abcde'
>>>str1[1:4:1]
'bcd'
>>>str1[0:4:2]
'ace'
>>>str1[-4]
'b'
>>>str1[-4:-1]
'bcd'
>>>str1[-4:-1:1]
'bcd'
>>>str1[-4:-1:-1]
'dcb'
>>>str1[::2] #default start is 0 and default end is (len(str)-1)
'aec'