About 364,000 results
Open links in new tab
  1. python - Using in range(..) in an if-else statment - Stack Overflow

    Aug 27, 2012 · python 2.7. Is it possible to do this: print "Enter a number between 1 and 10:" number = raw_input("> ") if number in range(1, 5): print "You entered a number in the range of …

  2. python - How do I create a list with numbers between two values ...

    Aug 16, 2013 · simple_range = [ x*0.1 for x in range(-100, 100) ] By changing the range count to 100 I now get my range of -10 through 10 by using the standard range function. So if you need …

  3. How does the Python's range function work? - Stack Overflow

    [Update: for Python3 (the currently maintained versions of Python) the range() function always returns the dynamic, "lazy evaluation" iterator; the older versions of Python (2.x) which …

  4. python - range() for floats - Stack Overflow

    Dec 6, 2015 · Is there a range() equivalent for floats in Python? >>> range(0.5,5,1.5) [0, 1, 2, 3, 4] >>>; range(0.5,5,0.5) Traceback (most recent call last): File "<pyshell#10 ...

  5. Print a list in reverse order with range ()? - Stack Overflow

    Sep 2, 2011 · $ python -m timeit "range(10)[::-1]" 1000000 loops, best of 3: 0.743 usec per loop Michał Šrajer's answer (the accepted one, very readable): $ python -m timeit …

  6. Python 3 turn range to a list - Stack Overflow

    Jul 14, 2012 · Use Range in Python 3. Here is a example function that return in between numbers from two numbers def get_between_numbers(a, b): """ This function will return in between …

  7. Python range () with negative strides - Stack Overflow

    For your case using range(10,-10,-1) will be helpful. The first argument refers to the first step, the second one refers to the last step, and the third argument refers to the size of that step. When …

  8. python - Why do we use "i" in loops such as in "for i in range ...

    Feb 4, 2018 · When you use a range loop you are saying that you want to count one by one from one number until you hit another. Typically it would look like this. for i in range(0, 5): This …

  9. range - Even numbers in Python - Stack Overflow

    Feb 2, 2010 · We will use the itertools module and more_itertools 1 to make iterators that emulate range(). import itertools as it import more_itertools as mit # Infinite iterators a = it.count(0, 2) b …

  10. How do I use variables in a loop with range ()? (Python)

    Dec 26, 2013 · If you use Python 2.X you also can optimize your code - instead of range you might use xrange. It works much faster. for i in xrange (l): #Do something (like append to a list) …

Refresh