Python Input & Output

Input & Output in Python
In this article, we will see different ways in which first we can take input from users and second show output to them.
How to Take Input From User in Python
Sometimes a developer might want to take user input at some point in the program. To do this Python provides an input() function.
Syntax :
input('Message')
where Message is an optional string that is displayed on the string at the time of taking input.
Example 1: Python get user input with a message
# Taking input from the user
name = input("Enter your name: ")
# Output
print("Hello, " + name)
print(type(name))
Output:
Enter your name: CodeHind
Hello, CodeHind
Note:Python takes all the input as a string input by default. To convert it to any other data type we have to convert the input explicitly. For example, to convert the input to int or float we have to use the int() and float() method respectively.
Example 2: Integer input in Python
# Taking input from the user as integer
num = int(input("Enter a number: "))
sum = num + 1
# Output
print(sum)
Output:
Enter a number: 29
30