Python3 string slicing

Joined
Mar 29, 2023
Messages
14
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
106
Reaction score
26
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
14
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

Members online

No members online now.

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top