<p>您需要在二进制数前面加上<code>0b</code>:</p>
<pre><code>"""Sistema de Cifrado Vernam"""
#alfabeto
alfabeto = {"a":0b00011,"b":0b11001,"c":0b01110,"d":0b01001,"e":0b00001,"f":0b01101,"g":0b11010,"h":0b10100,"i":0b00110,"j":0b01011,"k":0b01111,"l":0b10010,"m":0b11100,
"n":0b01100,"o":0b11000,"q":0b10111,"r":0b01010,"s":0b00101,"t":0b10000,"u":0b00111,"v":0b11110,"w":0b10011,"x":0b11101,"y":0b10101,"z":0b10001,
"<":0b01000,"=":0b00010,"fdown":0b11111,"fup":0b11011," ":0b00100, "":0b00000}
"""Mensaje en texto plano"""
#Susituir por input
mensaje = "stack"
m = []
for e in mensaje:
m.append(alfabeto[e])
print m
</code></pre>
<p>该输出:</p>
^{pr2}$
<p>关于为什么<code>0b</code>是必需的详细信息可以在这里找到:<a href="https://docs.python.org/2.7/reference/lexical_analysis.html#integer-and-long-integer-literals" rel="nofollow">https://docs.python.org/2.7/reference/lexical_analysis.html#integer-and-long-integer-literals</a></p>
<p><strong>附录,以回答问题的后续编辑:</strong></p>
<p>如果要将输出格式化为二进制,请使用<a href="https://docs.python.org/2.7/library/functions.html#bin" rel="nofollow"><em>bin()</em></a>或<a href="https://docs.python.org/2.7/library/functions.html#format" rel="nofollow"><em>format()</em></a>:</p>
<pre><code>>>> [format(e, '05b') for e in m]
['00101', '10000', '00011', '01110', '01111']
</code></pre>