Python:如何将列表中的所有值转换为其ascii值?

时间:2015-03-31 10:09:11

标签: python list ord

def encrypt_message(text, x):
  text = list(text)
  for y in text:
    ord(text)

返回ord()期望长度为1的字符串,但找到列表

1 个答案:

答案 0 :(得分:1)

问题是您已将text传递给ord函数,您需要传递y

但是因为字符串是可迭代的对象,所以你可以循环遍历字符串:

def encrypt_message(text, x):
     return [ord(i) for i in text]