+ 1

Python read variable

I have a very important question! I am a new in python and for days I try to figure out how can I read any variable I want! In C++ is easy: if you want to read 1 3 and 4, what you need to do is to write function “cin” with three variables, like this: cin >> x >> y >> z. Also it works if the numbers is on column. (Like: 1 3 4) In python it doesn’t work any way! I find that in python I can read a variable with input() function!

1st Aug 2019, 4:37 PM
~ 꼰스탄틴 오니씸 ~
~ 꼰스탄틴 오니씸 ~ - avatar
7 Respostas
0
I think I understand... something like this? x,y,z=map(int,input().split())
1st Aug 2019, 4:49 PM
Steven M
Steven M - avatar
+ 1
yes n3v375! Like this! I understand now! but is any method to convert to int all variable in int exactly when we read it?
1st Aug 2019, 4:56 PM
~ 꼰스탄틴 오니씸 ~
~ 꼰스탄틴 오니씸 ~ - avatar
+ 1
Thanks a lot 🤗
1st Aug 2019, 5:17 PM
~ 꼰스탄틴 오니씸 ~
~ 꼰스탄틴 오니씸 ~ - avatar
0
But, even so, I can read a variable like the second part of the top! but if i want to read like the first part, then it will be an eror!
1st Aug 2019, 4:38 PM
~ 꼰스탄틴 오니씸 ~
~ 꼰스탄틴 오니씸 ~ - avatar
0
and I find now something like this: input().split()
1st Aug 2019, 4:53 PM
~ 꼰스탄틴 오니씸 ~
~ 꼰스탄틴 오니씸 ~ - avatar
0
but why I cannot read as int (input().split())?
1st Aug 2019, 4:54 PM
~ 꼰스탄틴 오니씸 ~
~ 꼰스탄틴 오니씸 ~ - avatar
0
"yes n3v375! Like this! I understand now! but is any method to convert to int all variable in int exactly when we read it?" Nothing comes to mind, input() produces a string, but you can always change the variable type with int(input()). int(input().split()) does not work with multiple integers, because integers are not iterable, in this example strings or bytes are allowed. That is why the map function works, we provide multiple variables, to the map(), which takes 2 arguments, the variable type and user input. The split() function separates the integers by whitespace
1st Aug 2019, 5:08 PM
Steven M
Steven M - avatar