失望的跑步鞋 · 绍兴市妇幼保健院临床全外显子、基因芯片及单基 ...· 1 月前 · |
霸气的大蒜 · 【大型软件开发】浅谈大型Qt软件开发(一)开 ...· 1 月前 · |
销魂的风衣 · 北京市房山区人民政府_ 通知公告· 5 月前 · |
无邪的单杠 · 19年前的今天,艾弗森一战封神 - 知乎· 10 月前 · |
好帅的棒棒糖 · 刻晴大战史莱姆游戏破解版下载-刻晴大战史莱姆 ...· 1 年前 · |
In this post, We will see how to take integer input in Python. As we know that Python’s built-in input() function always returns a str(string) class object. So for taking integer input we have to type cast those inputs into integers by using Python built-in int() function.
Let us see the examples:
Example 1:
10 20 30 40 50 60 70 array: ['10', '20', '30', '40', '50', '60', '70'] 10 20 30 40 50 60 70 array: [10, 20, 30, 40, 50, 60, 70]
Example 4:
# input size of the list
n
=
int
(
input
(
"Enter the size of list : "
))
# store integers in a list using map, split and strip functions
lst
=
list
(
map
(
int
,
input
(
"Enter the integer elements of list(Space-Separated): "
).strip().split()))[:n]
print
(
'The list is:'
, lst)
# printing the list
Output:
Enter the size of list : 4 Enter the integer elements of list(Space-Separated): 6 3 9 10 The list is: [6, 3, 9, 10]