Today, we’ll be looking at how to capitalize a string in Python. There are a few built-in functions for this problem, but we can also roll our own solution.In short, the capitalize() method exists for this purpose. That said, if you need something a bit different than what this ...
在Python 中使用string.title()方法将每个单词首字母大写 在Python 中使用string.capwords()方法大写每个单词 在Python 中使用string.split()和string.join()方法将每个单词大写 本教程将解释在 Python 中大写字符串中每个单词的第一个字母的各种方法。如果我们有一个像hey! what's up?这样的字符串,我们想把它转换...
the of and to a in that is was he for it with as his on be at by i this had not are but from or have an they which one you were all her she there would their we him been has when who will no more if out so up said what its about than into them can only other time new...
在Python 中使用string.capwords()方法大寫每個單詞 string模組的string.capwords(string, sep)將字串作為第一個引數,將sep作為第二個引數,並返回帶有每個單詞大寫的第一個字元的字串,並以sep引數為基礎進行分隔。如果沒有給sep引數傳值或設定為None,則將使用空格作為分隔符,一個空格代替一個或多個空格。
string.title() メソッドは文字列の元の間隔を変更しません。以下のコード例は、string.title() メソッドを用いて Python で単語の各文字を大文字にする方法を示しています。string = "hey! what's up?" print(string) print(string.title()) ...