如何将列表中的整数转换为python中的字符串 [英] How to convert integers in list to string in python

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

问题描述

我想将 0 到 9 的整数转换为字符串.我能够通过像这样手动转换每个数字来做到这一点:

I want to convert the integers from 0 to 9 to strings. I was able to do it by manually transforming each number like this:

str(1) = a
str(2) = b

... 一直到 9 点.但是,这很慢,而且代码看起来不是很 Pythonic.我希望看到一种更快的编码解决方案,例如将所有这些数字放入一个列表中,然后将列表中的每个元素转换为一个字符串.我知道要制作上述列表,我应该这样做:

... All the way untill 9. However, this is slow and the code doesn't look very pythonic. I would like to see a faster to code solution, such as putting all these numbers into a list and then transforming each element inside the list to a string. I know that to make said list I should do it like this:

a = range(0,10)

但是,我不知道如何将列表中的整数转换为字符串.预先感谢您的帮助.

However, I don't know how to transform the ints inside the list to strings. Thanks in advance for your help.

推荐答案

您可以使用 map()str() 应用于数组中的每个值:

You can use map() to apply str() to each value in your array:

a = map(str, range(0, 10))

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

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