Python类型的变量给出了不同的答案

Python类型的变量给出了不同的答案,python,python-2.7,types,Python,Python 2.7,Types,我在读一个二进制文件,这里有两个字节,我用字节1和字节2 byte是一个列表 byte1 = byte[i] byte2 = byte[i+1] value1 = struct.unpack('B',byte1)[0], #this will be integer value2 = struct.unpack('B',byte2)[0] print type(value1) print type(value2) 但当我看到输出时,value1和value2都给出了不同的类型,而应该显示相同的

我在读一个二进制文件,这里有两个字节,我用
字节1
字节2

byte
是一个列表

byte1 = byte[i]
byte2 = byte[i+1]
value1 = struct.unpack('B',byte1)[0], #this will be integer
value2 = struct.unpack('B',byte2)[0]
print type(value1) 
print type(value2)
但当我看到输出时,value1和value2都给出了不同的类型,而应该显示相同的类型

输出:

<type 'tuple'>
<type 'int'>

我错过了什么


谢谢。

这行末尾有一个逗号:

value1 = struct.unpack('B', byte1)[0], #this will be integer
#                                    ^
逗号将右侧变成一个元组。考虑:

>>> a = 1,
>>> type(a)
<type 'tuple'>
>>> a = 'foo',
>>> type(a)
<type 'tuple'>

行的末尾有一个逗号:

value1 = struct.unpack('B', byte1)[0], #this will be integer
#                                    ^
逗号将右侧变成一个元组。考虑:

>>> a = 1,
>>> type(a)
<type 'tuple'>
>>> a = 'foo',
>>> type(a)
<type 'tuple'>

哦,我的上帝!巨蟒太神奇了。谢谢你,我明白了。哦,我的上帝!巨蟒太神奇了。谢谢你,我明白了。