![]() |
VOOZH | about |
By default input() function in Python helps in taking user input as string. If any user wants to take input as int or float, we just need to typecast it.
Example: Taking the default (string) user input:
Output
What color is rose?: Red
Red
We can typecast the user input to integer type by wrapping the input statement by int():
Output
How many roses?: 88
88 <class 'int'>
We can typecast the user input to float or decimal type by wrapping the input statement by int():
Output
Price of each rose?: 69.420
69.420 <class 'float'>