How to Get Input from User in Python

Last modified on January 16, 2021 18 sec read

Today we’re going to see how to get input from user in Python.

Table of Contents

  1. Input String
  2. Input Integer
  3. Input Float

Input String

We use input() function in Python to get user input.

main.py
var = input("Enter any string: ")
print(var)

Input Integer

We can take only integer input using int(input()).

var = int(input("Enter an Integer: "))
print(var)

Input Float

We can take only integer input using float(input()).

var = float(input("Enter a float value: "))
print(var)
That’s it. Thanks for reading. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.
Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

Your email address will not be published. Required fields are marked *