python 判断bytes是否相等的几种方法

时间:2024-03-09 11:35:33

一 前言:

 python判断bytes是否相等,一般要用到这几种方法:is,==,operator.下面做几个例子让大家看一下.

二 正文:

 

1 相等方法:

 

test1=b\'0xab\'
test2=b\'0xab\'


if test1 == test2:
        print("equeal is success")
else:
        print("not equal")

 

 

2 is 方法:

test1=b\'0xab\'
test2=b\'0xab\'

if test1 is test2:
        print("equeal is success")
else:
        print("not equal")

 

 

3 operator方法:

 

 1 import operator
 2 
 3 test1=b\'0xab\'
 4 test2=b\'0xab\'
 5 
 6 result = operator.eq(test1,test2)
 7 
 8 print("result:"+str(result))
 9 
10 test3=b\'0xad\'
11 test4=b\'0xab\'
12 result = operator.eq(test3,test4)
13 
14 print("result:"+str(result))