input() function Flashcards
What is input() function used for?
The input() function is used to accept the value for a variable from the user.
How to input integer and float values?
To input integer and float values, use int() or float() along with input().
What data type does the input() function take by default?
In Python, input() function takes one string argument, which means that whatever value is being entered by the user will be taken as a string argument.
What happens when you do not write int()?
When you do not write int() along with input(), it takes the values as string and joins them instead of adding them.
What would happen if you tried to multiply without adding int()?
When you try to multiply without writing int(), it gives an error as you cannot multiply string values.
What happens when you use the int() function?
When you use the int() function along with the input() function, it considers the values as integers and they can now be added or multiplied like normal.