homework5git/lists/range02.py

22 lines
590 B
Python

# This code is based on: https://www.w3schools.com/python/ref_func_range.asp
x = range(3, 6)
# A range can be converted to a list.
y = list(x)
# Note:
# What is the difference betweeen using range() and an explicit list?
# The main difference is that range calculates the value on the fly. This saves memory
# at the expense of processing speed. The list has each object stored in memory. This saves
# the processing time at the expense of memory usage.
print(f"x = {x}, type = {type(x)}")
for item in x:
print(item)
print(f"y = {y}, type = {type(y)}")
for item in y:
print(item)