What does += mean in this context?

The line initials += name[0].upper() # append the initial adds the first character to a string, the process:

  1. Split a string into a list (So john doe becomes ['john', 'doe'])
  2. Iterate over each item in that list
  3. For each item in that list, append to the empty string the first character, capitialized
    For example, for john, get the first character j and capitalize it as J
  4. Return the initials (JD in this case)

Leave a Comment