map()函数的用法
str1 = "This is a cat"
mapper = map(str.upper, str1)
lst = list(mapper) # ['T', 'H', 'I', 'S', ' ', 'I', 'S', ' ', 'A', ' ', 'C', 'A', 'T']
# lst = ''.join(lst) # THIS IS A CAT
print(lst)
def to_upper(s):
return s.upper()
def my_join(s):
return ''.join(s)
new_str = list(map(to_upper, str1))
print(my_join(new_str)) # THIS IS A CAT
str2 = "How are you today?"
mystr2 = list(map(lambda x:x.upper(),str2))
print(my_join(mystr2)) # HOW ARE YOU TODAY?

浙公网安备 33010602011771号