0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

文字列をBoolに変換

Posted at

bool()は使いづらい

文字列型を変換したい場合、何か値が入っていればTrueが返ってくる

configparserと一緒に使おうとして、確かダメだったなーということで今更ながら関数作った。

自作関数で解決

最後のelseは不要

def get_bool(input: str) -> bool:
    if input.lower() == 'true':
        return True
    if float(input) >= 0:
        return True
    else:
        return False
0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?