python 文字列比較

python 文字列比較 ==、 !=、 is、 is not

str1 = 'test'
str2 = 'test'
print('str1=' + str1 + ' str2=' + str2)
print('str1 == str2 ' + str(str1 == str2))
print(str1 == str2)
if str1 == str2:
    print('== matched')
else:
    print('== unmatched')
print('str1 is str2 ' + str(str1 is str2))
print(str1 is str2)
if str1 is str2:
    print('is matched')
else:
    print('is unmatched')










print('\nstr1 != str2 ' + str(str1 != str2))
print(str1 != str2)
if str1 != str2:
    print('!= matched')
else:
    print('!= unmatched')
print('str1 is not str2 ' + str(str1 is not str2))
print(str1 is not str2)
if str1 is not str2:
    print('is not matched')
else:
    print('is not unmatched')


コメント

人気の投稿