How can I capitalize the first letter of a name in Python?

You can use the built-in string method capitalize() in Python to capitalize the first letter of a name.

Here is an example code:

name = "john smith"  # 姓名
capitalized_name = name.capitalize()  # 将姓名的首字母大写
print(capitalized_name)  # 输出 "John smith"

In this example, the original name string is “john smith”, then it is capitalized using the capitalize() method and assigned to the variable capitalized_name. Finally, the result is printed using the print() function.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds