简体   繁体   中英

How do I only change first letter into a capital using ascii in python

The code I currently have makes it so that the entire word is capitalised instead of just the first letter which is what I am trying to accomplish.

https://i.stack.imgur.com/4FgE7.png

There is a nice method for str called .capitalize()

word = "hello"
word.capitalize()
word = "pinklemon1998"

_word = word[0].upper() + word[1:]

Or as mentioned in the comments:

_word = word.title()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM