Input by User

User Input:

- User input means python takes the input from the user through the input() method.

- You can enter the input in the Output Terminal.

- In the below code, input is in string type.

- In the below code, if we enter the string or integer as input then we get the str type.

- We can enter string, integer, and float values in the input without getting any error

- Syntax: variable_name = input("Type anything: ")
               print(variable_name)


Output:

- We can enter the input in the output.





- We changed the type of input (string to integer).

- In the below code, if we enter an integer in the input then we get the int type, if we enter a string in the input then python throws an error.

- We can enter only integer values in the input (Use this input when you need only integer values)

Syntax: variable_name = int(input("Type anything: "))
               print(variable_name)


Comments