python如何将几个数字或者字符输入到一个列表或者字符串中在一行输出
3 回答
![?](http://img1.sycdn.imooc.com/533e4d5b0001d57502200203-100-100.jpg)
长风秋雁
TA贡献1757条经验 获得超7个赞
1,整数字符串转换为对应的整数
int('12')
2,小数字符串转换为对应小数
float('12.34')
3,数字转换为字符串
str(123.45)
4,ASCII码转换为相应字符
chr(97)
5,字符转换为响应ASCII码
ord('a')
![?](http://img1.sycdn.imooc.com/545863e80001889e02200220-100-100.jpg)
达令说
TA贡献1821条经验 获得超6个赞
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/54585094000184e602200220-100-100.jpg)
哔哔one
TA贡献1854条经验 获得超8个赞
以下代码调试通过:
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
提交
取消