+ 4
Please can some one explain,me this function :- int(input() )
28 Answers
+ 13
input() is a function used to take user input, for example asking user to enter a name for game etc. Anything given by user will be of type str.
int() is a function which is used to convert type str to type int
So, int(input()) means takes user input as str and then make it int.
+ 7
visph , He/she is a beginner that's why I just say str š
+ 4
input() take an input as a string...
int(input()) take an input and cast it to an int...
+ 2
You can check this lesson:
https://www.sololearn.com/learning/2426/
+ 1
The input() function takes input from the user which is in string format. So even if you enter a numerical value through the keyboard, it will be in str format due to which it cannot be evaluated through computation. The int(input()) converts the str into an int type.
+ 1
input() is used to take input from user .. , and int is used to convert that users input to integer.. as any input given by user is of type str.
+ 1
int(input())
The input () function is used to take the value from the user. The value is not defined in the program.
By default, the value type will be a string(str). To convert a value type into an integer, the int keyword is used.
+ 1
That function takes only integer input of the user
+ 1
input() is a function in Python for taking string as a input but if you take integer as a input then you have to write int before the input function (int(input()). If you write eval(input()) then interpreter automatically unerstand the data type enter bye the user. That's all
+ 1
input() is used to take input from a user . If the data type of the input is different from integer datatype, is then you can convert it into integer data type using the int keyword.
+ 1
Very simple, read built in function of python.
0
visph Where is the input stored when we type something (without pressing enter) in the command prompt? Is it stored in the memory allocated to the command prompt process?
0
Calvin Thomas input() read characters from standard input (stdin) logical file stream provided by the terminal / command prompt, until a new line char is encounteted...
this stream (and stdout / stderr) is created by os for the process wich run your programm... so in a sense, it is "stored in the memory allocated to the command prompt process" (in fact it is stored in specific buffer in memory allocated at the layer of the os, and available for the terminal / command prompt process)
https://en.m.wikipedia.org/wiki/Standard_streams
0
Rishav Tiwari int() is a function wich is used to initialize an int: it is a class, and its __init__ method has the signature (x, base=10)...
if the argument provided cannot be converted to an int, it raise an exception... but that argument would not be necessarly a string ;P
0
Rishav Tiwari as you explained what is int(), it would have been more right to say "is a function wich is used to convert any value to type int, or raise exception if it's not possible" ^^
0
visph Thank you. So "stdin" means the keyboard? I'm confused about what the standard input is. Is "read from stdin" the same as "read from the keyboard"?
0
Calvin Thomas in most of case, yes... but stdin is an abstraction and can be other source: read the wikipedia article wich I have linked in my previous answer to learn more about standard streams ^^
0
visph Thank you very much.
0
It simply means the input data should be of type integer or whole number
0
It converts the user input to an integer so you can use it for maths
For example:
var = int(input())
print(var+1)