In Python 2.x:
range
creates a list, so if you dorange(1, 10000000)
it creates a list in memory with9999999
elements.xrange
is a sequence object that evaluates lazily.
In Python 3:
range
does the equivalent of Python 2’sxrange
. To get the list, you have to explicitly uselist(range(...))
.xrange
no longer exists.
Related Posts:
- what does +=, -=, *= and /= stand for in Python?
- NameError: global name ‘xrange’ is not defined in Python 3
- Name ‘xrange’ is not defined in Python 3 [duplicate]
- Traverse a list in reverse order in Python
- When to use “while” or “for” in Python
- python “TypeError: ‘numpy.float64’ object cannot be interpreted as an integer”
- Python – TypeError: ‘int’ object is not iterable
- Why there is no do while loop in python
- What is the difference between rw+ and r+
- Python – TypeError: ‘int’ object is not iterable
- Accessing the index in ‘for’ loops?
- Python division
- Accessing the index in ‘for’ loops?
- raw_input function in Python
- Safest way to convert float to integer in python?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Print a list in reverse order with range()?
- write() versus writelines() and concatenated strings
- How to iterate over a JavaScript object?
- No module named MySQLdb
- No module named MySQLdb
- How do you use subprocess.check_output() in Python?
- How can I concatenate str and int objects?
- Pythonic way to combine FOR loop and IF statement
- Subplot for seaborn boxplot
- How do you use subprocess.check_output() in Python?
- What does `<>` mean in Python?
- Exit while loop in Python
- While Loop in Mips (New to Mips)
- Pythonic way to iterate through a range starting at 1
- Pop index out of range
- While, Do While, For loops in Assembly Language (emu8086)
- Angular 2 Cannot find control with unspecified name attribute on formArrays
- Loop backwards using indices in Python?
- Why does using from __future__ import print_function breaks Python2-style print?
- Guess a number program with Java
- Python – ‘ascii’ codec can’t decode byte
- How to return dictionary keys as a list in Python?
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- Breaking out of nested loops
- Is there a “do … until” in Python?
- Iterating over a 2 dimensional python list [duplicate]
- Infinite for loops possible in Python?
- Using multiple variables in a for loop in Python
- python: restarting a loop
- Python, Matplotlib, subplot: How to set the axis range?
- range() for floats
- What is the best way of determining a loop invariant?
- Why does Lua have no “continue” statement?
- built-in range or numpy.arange: which is more efficient?
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- How do you write code to do factorials in MIPS?
- Python loop counter in a for loop
- Get a Try statement to loop around until correct value obtained
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Printing from a declared array in MIPS
- Using print() (the function version) in Python2.x
- Python: Continuing to next iteration in outer loop
- How to read a CSV file from a URL with Python?
- How to import a csv-file into a data array?
- Python SyntaxError :’return’ outside function
- Datetime strptime in python
- Python error “ImportError: No module named”
- How do I append one string to another in Python?
- What do these operators mean (** , ^ , %, //)? [closed]
- Is there a simple, elegant way to define singletons? [duplicate]
- How can I use the apply() function for a single column?
- positional argument follows keyword argument
- Convenient way to deal with ValueError: cannot reindex from a duplicate axis
- TypeError: ‘str’ object cannot be interpreted as an integer [duplicate]
- Updating matplotlib in virtualenv with pip
- Is the standard Python implementation considered as a programming language or a scripting language?
- Python – from . import
- SystemError: Parent module ” not loaded, cannot perform relative import
- How to remove anaconda from windows completely?
- SyntaxError: non-default argument follows default argument
- Python Package bt: Bool index error
- Python list sort in descending order
- How to do while loops with multiple conditions
- TypeError: ‘<=' not supported between instances of 'str' and 'int' [duplicate]
- enumerate() for dictionary in python
- How to convert a PIL Image into a numpy array?
- How to get autocomplete in jupyter notebook without using tab?
- Print list without brackets in a single row
- Get first row value of a given column
- AttributeError: ‘module’ object has no attribute
- In Python How can I declare a Dynamic Array
- Python module for converting PDF to text
- from sys import argv – what is the function of “script”
- Using sudo with Python script
- What does the Ellipsis object do?
- How to concatenate items in a list to a single string?
- python pip on Windows – command ‘cl.exe’ failed
- pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
- Rename specific column(s) in pandas
- How to create a numpy array of lists?
- Counting array elements in Python
- What is the maximum float in Python?