生成一串数字python [英] Generate string of numbers python

查看:68
本文介绍了生成一串数字python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想创建一个字符串列表,其中每个字符串都是一个数字.

Hello I want to create a list of strings where each string is a number.

给出数字 4 的 Fox 示例 我想创建一个函数,该函数返回一个包含元素 '0'、'1'、'2'、'3'、'4' 的列表.在 C/C++ 中,这可以通过使用 0 的 Ascii 代码然后增加它们来完成.我是 Python 新手,不知道该怎么做.有什么办法吗?

Fox example given the number 4 I would like to create a function that returns a list with elements '0','1','2','3','4'. In C/C++ this can be done by using the Ascii code of 0 and then increase them. I am new to python and I don’t know how to do it. Is there any way to do it?

推荐答案

你可以像这样使用 strrange 来做到这一点

You can do this with str and range like this

map(str, range(number + 1))

number = 4时,

print(map(str, range(4 + 1)))
# ['0', '1', '2', '3', '4']

这篇关于生成一串数字python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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