+ 1

How to print even/odd numbers without using % and / or //... Using slicing

Pyhton

21st Jul 2019, 7:19 AM
Akki Dubey
Akki Dubey - avatar
2 Answers
+ 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]
21st Jul 2019, 7:26 AM
Airree
Airree - avatar
+ 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
21st Jul 2019, 7:05 PM
Choe
Choe - avatar