Taking User Input in Python

Photo by Jess Bailey on Unsplash

Taking User Input in Python

Table of contents

In Python, we can take user input directly by using the input() function. This input function gives a return value as a string/character hence we have to pass that into a variable.

Syntax:

variable=input()

But the input function returns the value as a string. Hence we have to typecast them whenever required to another datatype.

Example:

variable=int(input())

variable=float(input())

We can also display text using the input function. This will make the input() function take user input and display a message as well

Example:

a=input("Enter the name: ")

print(a)

Enter the name: Hello

Hello