python3在同一行内输入n个数并用列表保存的例子
作者:JC04 时间:2023-05-18 04:10:47
最近在学习算法,经常遇到一行有多个数据,用空格或者','进行分割。最开始不懂,直接百度,
n = input()
n = int(n)
list1 = []
list1 = input().split()
list2 = []
i = 0
while i < n:
m = int(list1[i])
list2.append(m)
i += 1
print(list2)
但是这样代码量太多了。看起来也很啰嗦。
自己无意实验一下得到一个新方法:
list1 = list(map(int,input().split()))
还不错,大家可以试试哦!
来源:https://blog.csdn.net/qq_14841239/article/details/82903445
标签:python3,输入,n个数,列表,保存
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现乱序文件重新命名编号
2021-05-20 09:07:04
![](https://img.aspxhome.com/file/2023/3/75313_0s.png)
MySQL增删查改数据表详解
2024-01-25 06:55:48
![](https://img.aspxhome.com/file/2023/3/107713_0s.png)
Python实现AI自动玩俄罗斯方块游戏
2021-11-16 23:11:41
![](https://img.aspxhome.com/file/2023/2/103682_0s.jpg)
连接Python程序与MySQL的教程
2024-01-26 15:02:57
详解Vue-cli webpack移动端自动化构建rem问题
2024-04-29 13:40:06
谈谈网页设计中的字体应用 (3) 实战应用篇·上
2009-11-24 13:09:00
![](https://img.aspxhome.com/file/UploadPic/200911/24/202939796-72s.gif)
python中networkx函数的具体使用
2023-01-05 12:29:16
![](https://img.aspxhome.com/file/2023/6/133816_0s.png)
浅析Flask如何使用日志功能
2023-06-17 17:18:21
Python中除法使用的注意事项
2021-11-07 07:18:17
python实现查找两个字符串中相同字符并输出的方法
2023-09-01 04:03:42
解决python3中cv2读取中文路径的问题
2023-05-17 18:52:10
pygame可视化幸运大转盘实现
2021-03-01 05:22:11
![](https://img.aspxhome.com/file/2023/7/79607_0s.png)
SQL Server下几个危险的扩展存储过程
2024-01-18 06:49:25
Python实现读取目录所有文件的文件名并保存到txt文件代码
2023-08-28 19:27:51
django第一个项目127.0.0.1:8000不能访问的解决方案详析
2021-05-21 14:01:38
![](https://img.aspxhome.com/file/2023/0/90560_0s.png)
PHP结构型模式之代理模式
2023-05-25 06:55:34
asp如何让页面背景五彩缤纷?
2010-05-13 16:38:00
JDBC连接MySQL数据库关键的四个步骤
2009-12-17 12:06:00
Python实现的扫码工具居然这么好用!
2022-12-13 19:54:03
Python Pandas处理CSV文件的常用技巧分享
2022-06-18 12:56:19
![](https://img.aspxhome.com/file/2023/1/99621_0s.png)