このエントリーをはてなブックマークに追加


英字の大文字・小文字を区別せず比較する方法・re

Pythonで英字の大文字・小文字を区別せずに比較する方法のサンプルコードを以下に記します。


スポンサーリンク

関連記事

英字の大文字・小文字を区別しないサンプルコード

lower, upper, 正規表現のreモジュールを使ったサンプルコードです。

import re

a = "HELLO WORLD"
b = "hello world"

if a == b:
    print "same stringl\n"
if a.upper() == b.upper():
    print "upper() : same string"
if a.lower() == b.lower():
    print "lower() : same string"

if re.compile(a,re.IGNORECASE).match(b) != None:
    print "re.cmpile... : same string"

実際に実行した時の出力です。

$ python cmp.py
upper() : same string
lower() : same string
re.cmpile... : same string

以上、Pythonで英字の大文字・小文字を区別せずに比較する方法でした。


スポンサーリンク


添付ファイル: filecmp.py 585件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-03-20 (金) 22:31:28