I'm an absolute beginner and have read many related topics but I just can't get my mind around it.
I try to create a function which iterates through the string s exactly "n" times.
s="hello"
n=2
If I simply type in
s[::n]
it does work, however, if I try to express this in a function everything goes haywire.
My function looks like this:
def printEvery(s,n):
for n in range(len(s)):
print(s[::n])
ValueError: slice step cannot be zero
I really don't get why it doesn't work in a function as in my head it only makes sense this way. I'd deeply appreciate any help.
E: Sorry for the format and thank you for the edit khelwood!
range
starts at 0, you cannot slice a string to return every zero-th element. – Christian König May 18 '17 at 10:57len(str) * n ^ -1
.printEvery('a'*206,None)
is great on a 1680x1050 monitor, using windows maximised python command line. – Nick May 18 '17 at 11:19