python title()返回标题化字符串
title()方法描述
title()方法属于python内置的字符串类实例方法,可用于返回一个“标题化”的字符串,即英文的首字母为大写,然后其余的字母为小写。
title()语法及参数
str.title()
python的title()字符串方法,一般情况下不接收参数。
title()返回值
python字符串str,一个新的字符串,不修改原字符串。
title()方法实例代码
>>> str = 'tHis iS a Title example.'
>>> str.title()
'This Is A Title Example.'
>>> str.title(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: title() takes no arguments (1 given)
实例代码解析
title() takes no arguments,即python的title()方法不接收任何参数,否则python会抛出TypeError。