About 11,200,000 results
Open links in new tab
  1. 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 returned a statically allocated list of integers are now officially obsolete (after years of …

  2. 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 1 to 5" elif number in range(6, 10): print "You entered a number in the range of 6 to 10" else: print "Your number wasn't in the correct range"

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

    Mar 28, 2012 · 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 your range is ascending, you do not need to specify the steps if you need all numbers between, range(-10,10) or range(-10,-5).

  4. 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 it by 0.2 then just do range(-200, 200) and so on etc

  5. python - How to set the axis limits in Matplotlib? - Stack Overflow

    One thing you can do is to set your axis range by yourself by using matplotlib.pyplot.axis. matplotlib.pyplot.axis. from matplotlib import pyplot as plt plt.axis([0, 10, 0, 20]) 0,10 is for x axis range. 0,20 is for y axis range. or you can also use matplotlib.pyplot.xlim or matplotlib.pyplot.ylim. matplotlib.pyplot.ylim. plt.ylim(-2, 2) plt ...

  6. python - How to select a range of values in a pandas dataframe …

    I would like to select a range for a certain column, let's say column two. I would like to select all values between -0.5 and +0.5. How does one do this? I expected to use -0.5 < df["two"] < 0.5 But this (naturally) gives a ValueError: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). I tried

  7. python - Print a list in reverse order with range ... - Stack Overflow

    Sep 2, 2011 · $ python -m timeit "[9-i for i in range(10)]" 1000000 loops, best of 3: 1.54 usec per loop martineau's answer (readable if you are familiar with the extended slices syntax): $ 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):

  8. python - How can I access the index value in a 'for' loop? - Stack …

    Here, range(1, len(xs)+1); If you expect the output to start from 1 instead of 0, you need to start the range from 1 and add 1 to the total length estimated since python starts indexing the number from 0 by default.

  9. python - Determine whether integer is between two other integers ...

    Mar 8, 2023 · Below are few possible ways, ordered from best to worse performance (i.e first one will perform best) # Old school check if 10000 <= b and b <=30000: print ("you have to pay 5% taxes") # Python range check if 10000 <= number <= 30000: print ("you have to pay 5% taxes") # As suggested by others but only works for integers and is slow if number in …

  10. Python error: IndexError: list assignment index out of range

    Python does not dynamically increase the size of an array when you assign to an element. You have to use a.append(element) to add an element onto the end, or a.insert(i, element) to insert the element at the position before i.

Refresh