@@ -549,17 +549,24 @@ If you can do this, you will be happier than the vast majority of other programm
549549** Bad:**
550550
551551``` python
552- # Global variable referenced by following function.
553- # If another function used this name, now it'd be an array and could break.
552+ # This is a module-level name.
553+ # It's good practice to define these as immutable values, such as a string.
554+ # However...
554555name= ' Ryan McDermott'
555556
556557def split_into_first_and_last_name () ->None :
558+ # The use of the global keyword here is changing the meaning of the
559+ # the following line. This function is now mutating the module-level
560+ # state and introducing a side-effect!
557561global name
558562 name= name.split()
559563
560564split_into_first_and_last_name()
561565
562566print (name)# ['Ryan', 'McDermott']
567+
568+ # OK. It worked the first time, but what will happen if we call the
569+ # function again?
563570```
564571
565572** Good:**
@@ -586,6 +593,7 @@ class Person:
586593def name_as_first_and_last (self ) ->list :
587594return self .name.split()
588595
596+ # The reason why we create instances of classes is to manage state!
589597person= Person(' Ryan McDermott' )
590598print (person.name)# 'Ryan McDermott'
591599print (person.name_as_first_and_last)# ['Ryan', 'McDermott']