Python: Capitalize a word using string.format()

前端 未结 4 2079
萌比男神i
萌比男神i 2021-02-01 06:39

Is it possible to capitalize a word using string formatting? For example,

\"{user} did such and such.\".format(user=\"foobar\")

should return \

4条回答
  •  暖寄归人
    2021-02-01 07:02

    In python 3.6 you can use fstrings now. https://realpython.com/python-f-strings/

    >>> txt = 'aBcD'
    >>> f'{txt.upper()}'
    'ABCD'
    

提交回复
热议问题