How To Get Input From Keyboard with Python raw_input with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/get-input-keyboard-python-raw_input-examples/
PINTEREST
PINTEREST
INSTAGRAM

Python provides different functions and methods in order to get input from user, system, network etc. raw_inputis a method used to get input from user from interactive shell. We will look different use cases for raw_input for python.

Syntax

The syntax of the raw_input changes according to python version. We will look for both of them but use Python 3 version in the examples.

Python 2

  • DATA is set to the provided data
  • PROMPT is the text which will shown during data input

Python 3

  • DATA is set to the provided data
  • PROMPT is the text which will shown during data input

Get and Print Age Example

In this example we will simply get the input data which is age. We will print some prompt and get value and than print the provided value. Use following code.

Get and Print Age Example

Get and Print Age Example

Convert To Integer

We may need to convert provided value into integer. We can use int() in order to convert to integer.

Selection Example

One of the most used situation for raw_inputor inputis selection examples. We provide some chooses and wait input according to selection. In this example we will get the age range of the user.

LEARN MORE  How To Generate Random Numbers In Linux

Selection Example

Selection Example

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/get-input-keyboard-python-raw_input-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)