特定の形式の文字列

joeSwan:

文字列が正しい形式であればどのように私はPythonで確認できますか?
私は、変数持つタグを、そしてそれがfomratにする必要があります0.0

たとえば、

tag = "1.0"

if tag != (is not in format **0.0**):
    print("not in tag")"
else:
    print("correct tag")"

bashのでは、このようになります

tag="10.0"
if [[ $tag != "${tag%.*}.${tag#*.}" ]]; then
    echo "wrong tag"
fi
膝:

最も単純な実装では、正規表現を使用することです:

if not re.search("^\d+\.\d+$", tag):
    #does not match

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=364916&siteId=1
おすすめ