Python:如何将列表中的所有值转换为ascii值?
返回ord()应为长度为1的字符串,但找到了list问题是您将Python:如何将列表中的所有值转换为ascii值?,python,list,ord,Python,List,Ord,返回ord()应为长度为1的字符串,但找到了list问题是您将文本传递给ord函数,您需要传递y 但由于字符串是可编辑对象,您可以在字符串上循环: def encrypt_message(text, x): text = list(text) for y in text: ord(text) 您可能想编写ord(y)而不是ord(text)?我想知道这个函数试图实现什么。没有使用x,不管它做什么,看起来都不像加密。 def encrypt_message(text, x):
文本
传递给ord
函数,您需要传递y
但由于字符串是可编辑对象,您可以在字符串上循环:
def encrypt_message(text, x):
text = list(text)
for y in text:
ord(text)
您可能想编写
ord(y)
而不是ord(text)
?我想知道这个函数试图实现什么。没有使用x,不管它做什么,看起来都不像加密。
def encrypt_message(text, x):
return [ord(i) for i in text]