+ 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!
7 Réponses
0
I think I understand... something like this?
x,y,z=map(int,input().split())
+ 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?
+ 1
Thanks a lot 🤗
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!
0
and I find now something like this: input().split()
0
but why I cannot read as int (input().split())?
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