Is there a way to assign an interval to a variable?
for example
my_string = "abcdef" my_interval = 1:3 print(my_string[my_interval])
I want to come back bc . However, the second line does not work.
bc
You need to use the python built-in slice() function to assign the slice variable. Your current syntax is not a valid python syntax.
slice()
slice
>>> my_string = "abcdef" >>> my_interval = slice(1, 3) >>> print(my_string[my_interval])