LoginSignup
0
0

More than 5 years have passed since last update.

Python > string > in > 大文字と小文字のチェック > if angleMeasure.lower() in ['radians','rad']:

Last updated at Posted at 2018-03-23
動作環境
ideone (Python 3.5)

  if angleMeasure in ['radians','RADIANS','rad','RAD']:
    adjust = np.pi/180

PyMieScattには上記のように4つのパターンのチェックをしている実装がいくつか見られる。

下記でいいと思う。

  if angleMeasure.lower() in ['radians','rad']:
    adjust = np.pi/180


def check_unit_original(angleMeasure):
    if angleMeasure in ['radians', 'RADIANS', 'rad', 'RAD']:
        print('in(org)')

def check_unit_lower(angleMeasure):
    if angleMeasure.lower() in ['radians', 'rad']:
        print('in(lower)')

def check_unit_in(angleMeasure):
    if 'rad' in angleMeasure.lower():
        print('in(in)')

alist = 'radians', 'RADIANS', 'rad', 'RAD'
for astr in alist:
    check_unit_original(astr)

for astr in alist:
    check_unit_lower(astr)

for astr in alist:
    check_unit_in(astr)
run
in(org)
in(org)
in(org)
in(org)
in(lower)
in(lower)
in(lower)
in(lower)
in(in)
in(in)
in(in)
in(in)

check_unit_in()はやり過ぎかもしれない。
radioactiveもひっかかる。

link

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0