+ 1
How to print even/odd numbers without using % and / or //... Using slicing
Pyhton
2 Antworten
+ 2
That is ab interesting question. As you SHOULD KNOW, list slicing can accept 3 numbers: starting point, ending point, stepping point, so if you got a list of numbers, you could do it like this:
[i for i in range(500)][1::2]
(or)
[i for i in range(500)][::2]
+ 1
yes you can slice, but its much better to use ranges parameters, start, stop and step, or n*2 (even) and n*2-1 (odd) rep. by every number