python中的列表视图差异

Hello There i am working on python project for my python course project so i need to get number from users so enter image description here

here is my test codes but the output is like that enter image description here

i want to store my imput datas like this one [2] not like this ['2'] what can i do for solve this. Thanks for help

评论
盛水冬
盛水冬

by declaring new variable as input and without declaring what type it is, python will adress the variable as string. you will need to convert your variable:

yinp= int(input("enter your number")

点赞
评论
小情歌
小情歌

请尝试以下方法:

yinp = int(input('enter your number'))

Explanation: By default python will take the inputs as string, you need to convert it to required type. In this case you need to convert into integer, int() is helpful for you.

点赞
评论