BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Getting Input from User in Python

By Chaitanya Singh | Filed Under: Python Examples

In this tutorial, we will see how to take input from user in Python programming language. We use input() function in Python to get user input.

Get String input from user

In this program we will see how to receive string input from user in Python.

# Python Program - Get String Input from User
str = input("Enter any string: ")
print(str)

Output:
Python String Input From User

Get Integer Input from user

As we have seen in the above example that when we receive the input using input() function it is considered as String. To convert the string input to integer we use the int() function over the received input.

# Python Program - Get Integer Input from User
num = int(input("Enter an Integer: "))
print(num)

Output:
Python Int Input User

Get Float Input from user

This is similar to what we have seen above, except that we use float() function to convert the received input into a float value.

# Python Program - Get Float Input from User
num = float(input("Enter a float value: "))
print(num)

Output:
Python Float Value Input

Related Posts:

  1. Get Input from User in Java
  2. Python Program to print Hello World

Leave a Reply Cancel reply

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

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap