开发者社区> 问答> 正文

如何从用户使用python中的for循环获取多个输入?

我正在制作一个基本程序,我想在其中将用户的多个输入存储在预定义列表中。我的方法:

exampleList = []
exampleList = input("Enter the choice of user1: ")
exampleList = input("Enter the choice of user2: ")
exampleList = input("Enter the choice of user3: ")
exampleList = input("Enter the choice of user4: ")
exampleList = input("Enter the choice of user5: ")
# I want to store 5 number inputs in examples list

但是我不想多次使用输入函数。所需输出:

exampleList = [2,3,5,4,1]

问题来源:stackoverflow

展开
收起
is大龙 2020-03-21 09:07:14 1118 0
1 条回答
写回答
取消 提交回答
  • 可以考虑引入split 如

    a,b=input("请输入两个数:").split() 请输入两个数:2 3 print(a,b) 2 3 print(type(a)) <class 'str'>

    2020-03-22 16:17:54
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载