Python3 string slicing

Joined
Mar 29, 2023
Messages
10
Reaction score
1
I am trying to learn Python3 and have come across Lists. I know that counting begins at 0 and ends at -1
But i am having some difficulty in understanding the following example:

S[6:1:-2] = A B C D E F G H I

Could someone please explain what is going on here please.
 
Joined
Dec 10, 2022
Messages
73
Reaction score
22
That is not valid syntax

Python:
#Creates String
S = 'A B C D E F G H I'

# 6 print the sixth character :1 go back one character : -2 Go back two characters from sixth character
print(S[6:1:-2])

Output
Code:
DCB
 
Joined
Mar 29, 2023
Messages
10
Reaction score
1
Very big thanks menator01 for taking the time out to reply and of course the explanation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top