转换一个字符串,使第一个字母为大写,而everythingelse为小写

use*_*998 4 python

可能重复:
如何将字符串中每个单词的首字母大写(Python)?

是否有一个选项来转换一个字符串,使得第一个字母是大写,而everythingelse是小写....如下所示..我知道有上部和下部转换为大写和小写....

string.upper() //for uppercase 
string.lower() //for lowercase
 string.lower() //for lowercase

INPUT:-italic,ITALIC

OUTPUT:-Italic
Run Code Online (Sandbox Code Playgroud)

http://docs.python.org/2/library/stdtypes.html

Ash*_*ary 20

只需使用str.title():

In [73]: a, b = "italic","ITALIC"

In [74]: a.title(), b.title()
Out[74]: ('Italic', 'Italic')
Run Code Online (Sandbox Code Playgroud)

help()str.title():

S.title() -> string

Return a titlecased version of S, i.e. words start with uppercase
characters, all remaining cased characters have lowercase.
Run Code Online (Sandbox Code Playgroud)


Sup*_*Guy 14

是的,只需使用capitalize()方法.

例如:

x = "hello"
x.capitalize()
print x   #prints Hello
Run Code Online (Sandbox Code Playgroud)

标题实际上将每个单词都大写,就好像它是标题一样.大写只会将字符串中的第一个字母大写.