Skip to content

Input function in Python

Input function in Python

Input function in Python allows user input . It reads a line from input, converts it to a string by removing the trailing newline, and returns it .

Syntax of input function in Python

input(prompt)

Parameters of input function in Python

prompt = Optional , it is a string , written to standard output without a trailing newline .

Return type of input function in Python

It returns a string .

Examples of input function in Python

Example 1: Take input with prompt

# taking input from user
name = input("Enter your name")
print(name)
Enter your nameRajkumar
Rajkumar
  • In the above code we have taken input from user using input function .
  • After executing the program the prompt given in input function will be printed . User needs to put their input after that prompt .
  • After giving the input user needs to press the Enter button .
  • After pressing the enter button rest portion of the program will be executed and print the user input
  • In our case , as we gave "Rajkumar" as input so it printed "Rajkumar" at the output screen .

we can also check below images for our reference –

Example 2: Take input without prompt

# taking user input without prompt
myString = input()
print("inputted string is :",myString)
I love Python
inputted string is : I love Python

In the above code we have taken input from user using input function but without using a prompt .

we can also check below images for our reference –

Thank you for reading this Article . If You enjoy it Please Share the article . If you want to say something Please Comment 

Leave a Reply