如何将数字列表转换为相应的chr() [英] How do i convert a list of numbers into their corresponding chr()

查看:140
本文介绍了如何将数字列表转换为相应的chr()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c = list(range(97, 121))

如果我打印,它将给 [97、98、99、100、101、102、103、104、105、106、107、108、109、110、111、112、113、114、115、116、117、118、119]

if i print this it will give [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]

这些数字中的每个chr()字符串都只是字母,但是当我打印c时如何将该列表转换为字母

each of these numbers chr() string is just the alphabet but how do i convert this list to the alphabet when i print c

c = list(range(chr(97),chr(121)))

给出一个错误.所以不是很确定如何一次转换它们,而不是一个个地

gives an error. so not really sure how to convert them all at once rather than doing them individually

谢谢

推荐答案

如果要将数字范围内的数字转换为字符,但是如果您已有一个要转换的整数列表,hivert的解决方案就非常好转换成字符,您可以像这样修改解决方案:

hivert's solution is really good if you want to convert a range of numbers into characters, but if you have a pre-existing list of integers that you want to convert into characters, you could adapt the solution like this:

intList = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]
charList = [chr( intList[i] ) for i in range( 0, len( intList ) )]

这篇关于如何将数字列表转换为相应的chr()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆