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?
- SyntaxError: unexpected EOF while parsing
- How do I lowercase a string in Python?
- How do I copy a file in Python?
- How can I reverse a list in Python?
- Manually raising (throwing) an exception in Python
- How do I copy a file in Python?
- can’t multiply sequence by non-int of type ‘float’
- Difference between del, remove, and pop on lists
- How can I reverse a list in Python?
- How to use the pass statement
- How to use filter, map, and reduce in Python 3
- What does enumerate() mean?
- Searching the student-t distribution table for values using python
- How to declare an array in Python?
- Does Python have a ternary conditional operator?
- For-each over an array in JavaScript
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- Pig Latin Translator
- What is the difference between Python’s list methods append and extend?
- How can I make a time delay in Python? [duplicate]
- TypeError: ‘int’ object is not subscriptable
- sphinx.ext.autodoc: Keeping names of constants in signature
- are there dictionaries in javascript like python?
- How do you round UP a number?
- Understanding slice notation
- Iterating over dictionaries using ‘for’ loops
- How to define a two-dimensional array?
- how to sort pandas dataframe from one column
- Why am I seeing “TypeError: string indices must be integers”?
- Understanding the main method of python [duplicate]
- How do you round UP a number?
- Understanding slice notation
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How do I update\upgrade pip itself from inside my virtual environment?
- How to open a file using the open with statement
- How to emulate a do-while loop?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array