Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Clean-Up Renaming the Palace

00:00 Just looking at the code as it is right now, if you wouldn’t know about this exercise and everything, it doesn’t look perfect. There are two things that bother me a little bit.

00:10 One is that we still have this global statement in line four that we don’t need, and in line 13 we define a variable named address, which has the “Python Palace” string but then in the next line you define the same variable name address with the return value of explore_basement().

00:29 One thing could be to rename the second address variable, but an actually more straightforward solution here is to not even define the address variable, but pass in the explore_basement() function call into the print() function right away.

00:46 So let’s take the function call from line 14 and pass it as an argument in line 15 in the print() function call and remove the address variable definition in line foue. Save and run the file, that’s always a good idea to see if everything works as expected.

01:06 And as you can see, it does so it still prints “Mouse House” in the last line, which is nice. And now let’s remove the global statement in line four where you have global address.

01:17 This line doesn’t make sense anymore at this point because for nostalgic reasons, you want to keep the “Python Palace” address, so you don’t want to override it with the “Cookie Cabinet”.

01:29 Although the Python palace string is not printed anywhere, you also don’t want to override it. So let’s remove the global statement, save and run the file.

01:40 And there we can see the output is still correct, the code looks much cleaner and that actually concludes the exercise.

Become a Member to join the conversation.