What are range and xrange?



What are range and xrange?..

Answer / Ravi Kiumar

Both `range()` and `xrange()` generate a sequence of integers, but they differ in how the values are generated. `range()` generates a list with all the values at once, while `xrange()` generates the values on-the-fly (without storing them in memory).nn```pythonnlist_range = list(range(5)) nxrange_obj = xrange(5)nprint(list_range) # Output: [0, 1, 2, 3, 4]nprint(list(xrange_obj)) # Output: [0, 1, 2, 3, 4]

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What is an elif in python?

1 Answers  


What is the tool used to check python code standards?

1 Answers  


What is python and why python?

1 Answers  


What does exit () do in python?

1 Answers  


Which is the invalid variable assignment from the below?

1 Answers  


Does python have polymorphism?

1 Answers  


Tell me is there a switch or case statement in python?

1 Answers  


How do I use python idle?

1 Answers  


What are class attributes in python?

1 Answers  


Is compiled python faster?

1 Answers  


Can you hack with python?

1 Answers  


What is the with statement in python?

1 Answers  


Categories