increase and decrease a slice value? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: increase and decrease a slice value? (/thread-30869.html) |
increase and decrease a slice value? - KEYS - Nov-10-2020 say i have a list [1,2,3,4,5,6,7] and id like to print, 3,4,5 then 2,3,4,5,6 finally 1,2,3,4,5,6,7 using a for loop, and a slice value within its body is it possible to add to a set slice value? as this doesn't work i will present it as pseudo code as an example to possibly better illustrate. inv=[1,2,3,4,5,6,7] for i in range(0,3,1): add=(inv[3-1:4+1]) print (add) The [3-1:4+1] being the pseudo part of the code for now as it doesn't increment on each pass. It only changes the value of the slice the one time. RE: increase and decrease a slice value? - deanhystad - Nov-10-2020 You should just try these things and see if they work. I do a lot of testing using the Python console built into IDLE or running python in a shell window. For just trying things like this it is much quicker than writing a program. You also have the advantage of built in interactive help.
RE: increase and decrease a slice value? - KEYS - Nov-10-2020 You nailed it XD thank you |