Currently:
Output:
For ex:
Output:
1 2 3 |
a = "abcde" print ( "b[::-1] : " , b[:: - 1 ]) print ( "b[5:0:-1] : " , b[ 5 : 0 : - 1 ]) |
Output:>>> b[::-1] : edcba
>>> b[5:0:-1] : edcb
Can a custom function be defined that avoids duplicity in typing?For ex:
1 2 3 4 5 |
def fuc(a) print (a, ":" , a) # change here fuc(b[:: - 1 ]) fuc(b[ 5 : 0 : - 1 ]) |
Output:>>> b[::-1] : edcba
>>> b[5:0:-1] : edcb