def capitalize(s, lower_rest=False): # print(s) # fooBar # fooBar # print(s.upper()) # FOOBAR # FOOBAR # print(s[:1].upper()) # F # F # print(s[1:].lower()) # oobar # oobar # print(s[1:]) # ooBar # ooBar # print(s[:1].upper() + (s[1:].lower() if lower_rest else s[1:])) ''' 成立执行的语句 if 条件 else 不成立执行的语句 ''' capitalize('fooBar') # FooBar capitalize('fooBar', True) # Foobar
2020-05-03