+ 1
Why cant i negative slice my value?
Guys im trying to negative slicing the string "Hello" but the output is just a blank space like nothing at all. But if i do the normal slicing it will just work fine. How? HELP!! This worked a = "Hello" print(a[0:3]) output -> Hel This didnt! a = "Hello" print(a[-1:-3]) output -> nothing i want it to print ll how? Help!!
6 Antworten
+ 2
No output because end (-3) comes before start (-1).
If you want output you can:
- swap start and end (a[-3:-1])
- instruct the interpreter to go backwards (a[-1:-3:-1])
+ 2
Take a look here, it's all explained.https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/?ref=app
+ 1
print(a[-1::-3])
there are tow colon(:)
+ 1
why do you need to put two colon?
+ 1
Every number express about indexes
First number : determind which number starting from it
Second number Explains how many will pass to the last number and the default is 1
Last number : The last number is not printed, but the number that precedes or is subtracted from index number 1 so that we know we will print to any number