Ask coding questions

← Back to all posts
Why it isn't printing any thing
IshanShrivas05 (0)

plz someone guide me , i'm new to coding and don't know much about it.

Answered by ch1ck3n (1620) [earned 5 cycles]
View Answer
Comments
hotnewtop
ch1ck3n (1620)

i think this is what you want:

mystr = "barry is a good boy"
print(mystr[1:18])
IshanShrivas05 (0)

@ch1ck3n no bro , i want it as it is [-1:-18]

ch1ck3n (1620)

@IshanShrivas05
https://stackoverflow.com/questions/509211/understanding-slice-notation

a[start:stop]

you're starting the string at -1, which is already impossible. you also can't stop at -18. so because the string is 19 letters long, my program stops the string at 18 characters. you can't stop string at -18 characters. it also starts at 1 characters. so it basically skips the first letter and remoes the last character.

xxpertHacker (860)

@ch1ck3n Doesn't slicing by negatives in Python wrap around to the end?

ch1ck3n (1620)

@xxpertHacker Indexing does but slicing doesn't in this case

IshanShrivas05 (0)

@ch1ck3n Now I got it bro....thankuuu:)

ch1ck3n (1620)

@IshanShrivas05 can you click the checkmark next to my name if it helped? thank you!

ch1ck3n (1620)

What do you want your code to do?