1. 程式人生 > 其它 >Python字串函式capitalize的用法:首字母大寫

Python字串函式capitalize的用法:首字母大寫

技術標籤:# 4.2 Pythonpython字串strcapitalize

str.capitalize()

返回原字串的副本,其首個字元大寫,其餘為小寫

# coding:utf-8

name = 'xiao mu'
info = 'hello 小慕'
_info = '小慕 hello'
number_str = '1314'

new_name = name.capitalize()
new_info = info.capitalize()
_new_info = _info.capitalize()
new_number_str = number_str.capitalize(
) print(new_name,"<-", name) print(new_info,"<-", info) print(_new_info,"<-",_info) print(new_number_str,"<-",number_str)

在這裡插入圖片描述