
Patrick B. answered 04/04/21
Math and computer tutor/teacher
NO !!!
YOU MUST DO TWO (2) STRING SLICES because the order of the characters
change and the String in Python is IMMUTABLE (cannot be changed)
As I have explained the second index gives you ONE LESS CHARACTER...
so if the second index is 7, for example, then you get indices 0-6.
#--------------------------------------------------------------------------------------
inputDateStr = "2001-08-11"
outbuff = inputDateStr[5:7] + "-" + inputDateStr[:4]
#first slice returns chars at index 5-6 which is 08
#2nd slice returns chars at index 0-3 which is 2001
#puts them together and output
print(outbuff)
DO YOU UNDERSTAND?