如何从python中的raw_input制作列表? [英] How to make a list from a raw_input in python?

查看:61
本文介绍了如何从python中的raw_input制作列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我将raw_input作为某些列表的输入.

So I am taking raw_input as an input for some list.

x= raw_input()

我在哪里输入1 2 3 4 如果仅输入数字,如何将其转换为整数列表?

Where I input 1 2 3 4 How will I convert it into a list of integers if I am inputting only numbers?

推荐答案

像这样:

string_input = raw_input()
input_list = string_input.split() #splits the input string on spaces
# process string elements in the list and make them integers
input_list = [int(a) for a in input_list] 

这篇关于如何从python中的raw_input制作列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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