Discuss / Python / 字母大写,其他小写.

字母大写,其他小写.

Topic source

霁天13

#1 Created at ... [Delete] [Delete and Lock User]

def fn(s): r = '' if s[0].islower(): r += s[0].upper() else: r += s[0] for i in range(1, len(s)): if s[i].isupper(): r += s[i].lower() else: r += s[i] return r

string = ['adam', 'LISA', 'barT']

string_changed = list(map(fn, string)) print(string_changed)

output: ['Adam', 'Lisa', 'Bart']


  • 1

Reply