Python 2.7.9 Demo - 005.字符串判空

 

#coding=utf-8

#!/usr/bin/python



str1 = None;

str2 = '';

str3 = ' ';



if str1 == None :

    print("str1 is none.");

else :

    print("str1 is not none.");



if str2 == None :

    print("str2 is none.");

else :

    print("str2 is not none.");



if str2 == None or len(str2) == 0 :

    print("str2 is none.");

else :

    print("str2 is not none.");



if str3 == None or len(str3.strip()) == 0 :

    print("str3 is none.");

else :

    print("str3 is not none.");

 

你可能感兴趣的:(python)