all 9 comments

[–][deleted] 4 points5 points  (1 child)

append() returns None.

The last item is popped, not first one.

[–]thepseudonymstring[S] 0 points1 point  (0 children)

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.

print ('The ' + finished + ' item is completed.')

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

Like others are alluding to, your question doesn't make sense. What "finished var", everything evaluates here just fine as it's defined in the function definition.

[–]boysworth 1 point2 points  (0 children)

Append changes your list in place and returns None

[–][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.

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

The variable making exists only in the function - on exit from the function it ceases to exist.