Python Input VS Raw_input – Learn to Take User input with 2 Demos

The input method of Python

Taking user input from the keyboard is generally required in programming languages. For example, a calculator, currency converter etc. that asks users to enter some value from the keyboard or keypad.

Python comes up with an input() method that allows programmers to take the user input.

Before 3.x version of Python, the raw_input() function was used to take the user input. The raw_input function of Python is removed in the latest version.

From version 3.x, this is replaced with Python input() function. While simply using the raw_input() will generate an error.

Examples of Python input() method

Following are a few examples of using the input function.

An example of taking user input

In the following example, the program asks the user name and age and then displays it by using the input method.

Python input method

See this example online

Suppose if you entered the name as [your name] and age = 35

It will display that information after taking the input.

The output will be:

Hello, [your name].

Your age is 35

Input with Leap year example

This example asks a user to enter a Year in four digits (2000, for example) and the program will display if the entered year is a leap year or not by using the input Python method.

See this example online

 

Further Reading: Python File Open