#navi(../)
* Pythonで文字列を半角英字の大文字小文字化方法・upper,lower [#x1a0c1fa]
Pythonで半角英字を大文字、小文字に変換するサンプルコードを以下に記します。

#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)

* 関連記事 [#o47d7654]
-[[Pythonで文字列置換・replace>Python/サンプル/文字列の置換・replace]]
-[[Pythonで数値を文字列に変換する・str>Python/サンプル/数値を文字列に変換する・str]]
-[[Pythonで指定した文字で分割し配列(list)に格納する方法・split>Python/サンプル/指定した文字で分割し配列(list)に格納する方法・split]]
-[[Pythonで左右のスペース削除・strip, lstrip, rstrip>Python/サンプル/左右のスペース削除・strip, lstrip, rstrip]]
-[[Pythonでリストに格納されている要素に区切り文字を指定し出力する・join>Python/サンプル/リストに格納されている要素に区切り文字を指定し出力する・join]]
-[[Pythonで文字列の半角英字の大文字小文字化方法・upper,lower>Python/サンプル/半角英字の大文字小文字化方法・upper,lower]]
-[[Pythonで文字列のleft,mid,rightを実現する方法>Python/サンプル/文字列のleft,mid,rightを実現する方法]]
-[[Pythonで前方・後方文字列検索・find,rfind>Python/サンプル/前方・後方文字列検索・find,rfind]]
-[[Pythonでゼロパティングする方法・zfill>Python/サンプル/ゼロパティングする方法・zfill]]
-[[Pythonで英字の大文字・小文字を区別せず比較する方法・re>Python/サンプル/英字の大文字・小文字を区別せず比較する方法・re]]

* upper(), lower()を使用して半角英字を大文字、小文字変換する [#q7bdb63c]
以下のサンプルコードは半角英字文字列を大文字、小文字に変換します。
 s = "HELLO, world!"
 
 print s + ".upper() -> " + s.upper()
 print s + ".lower() -> " + s.lower()

以下は実際に上記サンプルコードを実行した時の出力です。~
半角英字が大文字または小文字に変換されているのが確認できます。
 HELLO, world!.upper() -> HELLO, WORLD!
 HELLO, world!.lower() -> hello, world!

以上、upper(), lower()の使い方およびサンプルコードでした。

#htmlinsertpcsp(ll-btm.html,ll-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS