In python, the input from keyboard or user can take using input() function.
print(“Enter your name : “)
x=input()
print(“Hello,”+ x )
Output:
Enter your name :
Harish #input from keyboard
Hello,Harish
We can use following function also to accept input from keyboard
x=raw_input()
The difference is that raw_input() does not exist in Python 3.x, while input() does. Actually, the old raw_input() has been renamed to input()
Forms of input() functions:
1. if we want to skip print function then
x=input("Enter your name")
OR
x=raw_input("Enter your name")
2. if you want to specify type of input then
x=int(input("Enter integer number : "))
can also use.
Example:
def swap(num1,num2):
temp=num1
num1=num2
num2=temp
#Accept two numbers
num1=int(input("Enter first Number : ")
num2=int(input("Enter Second Nummber : ")
In above program we have accepted two integer numbers.