python如何将几个数字或者字符输入到一个列表或者字符串中在一行输出
3 回答
![?](http://img1.sycdn.imooc.com/54586431000103bb02200220-100-100.jpg)
温温酱
TA贡献1752条经验 获得超4个赞
1,整数字符串转换为对应的整数
int('12')
2,小数字符串转换为对应小数
float('12.34')
3,数字转换为字符串
str(123.45)
4,ASCII码转换为相应字符
chr(97)
5,字符转换为响应ASCII码
ord('a')
![?](http://img1.sycdn.imooc.com/5458502c00012d4a02200220-100-100.jpg)
蛊毒传说
TA贡献1895条经验 获得超3个赞
str1=""
str_list=[]
for i in range(5):
N=input("please enter the number:")
str1+=str(N)
str_list.append(str(N))
print str1
print str_list
![?](http://img1.sycdn.imooc.com/533e4d00000171e602000200-100-100.jpg)
繁华开满天机
TA贡献1816条经验 获得超4个赞
以下代码调试通过:
1 2 3 4 5 6 7 | l = []
for i in range(5): n = input("please enter the number:") l.append(n)
print('l:', l) |
运行效果:
1 2 3 4 5 6 7 8 | please enter the number:12 please enter the number:34 please enter the number:56 please enter the number:35 please enter the number:22 l: ['12', '34', '56', '35', '22']
Process finished with exit code 0 |
添加回答
举报
0/150
提交
取消