The line initials += name[0].upper() # append the initial
adds the first character to a string, the process:
- Split a string into a list (So
john doe
becomes['john', 'doe']
) - Iterate over each item in that list
- For each item in that list, append to the empty string the first character, capitialized
For example, forjohn
, get the first characterj
and capitalize it asJ
- Return the initials (
JD
in this case)