The input() function helps to take the user's input and return the output in a string format. The user can give the input either as a string or as a number format.
input([prompt]) #Where prompt is a string value
Takes a single parameter. Whatever the user typed it takes as an input parameter.
|Parameter||Description||Required / Optional|
|prompt||a string that is written to standard output (usually screen) without trailing newline||Optional|
input() function actually evaluates the input string and tries to run it as Python code and the output is returned as a string.
|string||a string by removing the trailing newline|
|If EOF||it raises an EOFError exception.|
# get input from user inputString = input() print('The inputted string is:', inputString)
Python is interesting. The inputted string is: Python is interesting
# get input from user inputString = input('Enter a string:') print('The inputted string is:', inputString)
Enter a string: Python is interesting. The inputted string is: Python is interesting
# take three values from user name = input("Enter Employee Name: ") salary = input("Enter salary: ") company = input("Enter Company name: ") # Display all values on screen print("\n") print("Printing Employee Details") print("Name", "Salary", "Company") print(name, salary, company)
Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google
# convert inout into int first_number = int(input("Enter first number ")) sec second number ")) print("\n") print("First Number:", first_number) print("Second Number:", second_number) sum1 = first_number + second_number print("Addition of two number is: ", sum1)
Enter first number 28 Enter second number 12 First Number: 28 Second Number: 12 Addition of two number is: 40