Python: 如何将列表中的所有值转换为它们的 ascii 值?
Python: How to convert all values in a list to their ascii values?
def encrypt_message(text, x):
text = list(text)
for y in text:
ord(text)
returns ord() 需要长度为 1 的字符串,但找到了列表
问题是您将 text
传递给了 ord
函数,您需要传递 y
。
但由于字符串是可迭代对象,您可以循环遍历字符串:
def encrypt_message(text, x):
return [ord(i) for i in text]
def encrypt_message(text, x):
text = list(text)
for y in text:
ord(text)
returns ord() 需要长度为 1 的字符串,但找到了列表
问题是您将 text
传递给了 ord
函数,您需要传递 y
。
但由于字符串是可迭代对象,您可以循环遍历字符串:
def encrypt_message(text, x):
return [ord(i) for i in text]