Added code for lecture 2026-11-10
This commit is contained in:
parent
5b630435ae
commit
07b9e54bf0
52 changed files with 1248 additions and 1 deletions
21
lecture20261110/lists/range02.py
Normal file
21
lecture20261110/lists/range02.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
# 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue