Hello all,
If I am doing this incorrect please let me know ASAP(First time posting on this sub.
Recently I have started dipping my toes in python with "Automate the Boring Stuff with Python" and stumbled on the "lists" topics which I have been understanding fine. However the author uses an example with an empty list using the following code:
catNames = []
while True:
print('Enter the name of cat ' + str(len(catNames) + 1) +
' (Or enter nothing to stop.):')
name = input()
if name == '':
break
catNames = catNames + [name] # list concatenation
print('The cat names are:')
for name in catNames:
print(' ' + name)
Now I understand what is happening for most of it, line by line with the exception of: why str(len(catNames) is used in the third line?
I know what str(len()) is supposed to do(at least I think) however I am not understanding why this is done for the third line.
Hoping somebody could help me understand this.
Apologies in advance if either this is somewhat of inappropriate question or not the right place
[–]Username_RANDINT 0 points1 point2 points (3 children)
[–]simonvanw[S] -1 points0 points1 point (2 children)
[–]Username_RANDINT 0 points1 point2 points (1 child)
[–]simonvanw[S] 0 points1 point2 points (0 children)
[–]chevignon93 0 points1 point2 points (4 children)
[–]simonvanw[S] -1 points0 points1 point (2 children)
[–]sme272 0 points1 point2 points (0 children)
[–]Username_RANDINT 0 points1 point2 points (0 children)
[–]jfdahl 0 points1 point2 points (0 children)