Python文字列モジュールのcapwords()メソッドの概要

文法

Syntax: string.capwords(string[, sep=None])
Return Value: Returns a formatted string after above operations.

説明文

デフォルトのsepパラメータの場合

capwords()メソッドは、スペースに応じてsplit()によって着信文字列をシーケンス分割し、シーケンスの最初の各文字を大文字にし、スペースを使用して返す文字列を形成します。

sepパラメータを指定する場合

split()関数はsep渡されたパラメーターを使用して、文字列を分割およびグループ化して渡します。

コード例

# imports string module 
import string 
sentence = 'Python is one of the best programming languages.'
# sep parameter is left None 
formatted = string.capwords(sentence, sep = None) 
print(formatted) // Python Is One Of The Best Programming Languages.

# sep parameter is 'o' 
formatted = string.capwords(sentence, sep = 'o') 
print('When sep = "o"', formatted) // When sep = "o" PythoN is oNe oF the best proGramming languages.

89の元の記事を公開しました 賞賛されました83 訪問3492

おすすめ

転載: blog.csdn.net/devin_xin/article/details/105394311