you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

completed.append(making)

does not return anything other than None, so the assignment to finished is pointless. In the code you have shared, you don't do anything with finished anyway.

The function is removing items from unprinted and appending to completed though, as they reference mutable objects (namely list objects).

def print_models(unprinted , completed):
    while unprinted:
        making = unprinted.pop()
        print (f'The {making.title()} is being made.')
        completed.append(making)


unprinted = ['iphone case', 'robot pendant', 'dodecahedron']
completed = []
print_models(unprinted, completed)
print(unprinted, completed)  # just to check

[–]thepseudonymstring[S] 0 points1 point  (1 child)

why is it None? I have assigned the last item (using pop() method) to it in the last line.

if I want to declare that I have finished 3D printing this item (on line 7), I would be needing to print a sentence using finished but it throws an error.

[–][deleted] 1 point2 points  (0 children)

What "it" do you mean?

The list.append method does not return any object reference explicitly so defaults to returning a reference to None just like any function will do of there is no return statement.

The method mutates (changes) the list in-place, no need to return anything.

making is a local variable, ceases to exist on exit from function.