When doing an exercise question, the topic is:
map()function to change the irregular English name entered by the user into capitalized first letters, and other canonical names in lowercase.
When writing at the beginning, capitalize the first letter directly as
name = name.upper()
then I got this error
TypeError:'str' object does not support item assignment
The reason is: In python, strings are immutable objects and cannot be directly assigned and modified by subscripts. The same immutable objects include numbers, strings, and tuples.
So the solution for this question should be
def normalize(name): return name.upper() + name[1:len(name)].lower() # test code L1 = ['liLEi', 'HAnMeimEI'] L2 = list(map(normalize, L1)) print(L2)