How to Input Variable in Python

Posted on

Introduction

This article will be the detail description about how to input variable in python exist in previous article. That article in this link which will direct to an actual article with the title of ‘How to Input in Python’. In that article, there is a part of the content which is showing in general about how to input variable in Python programming language. Actually, this article will focus on how to input variable in Python programming language. Specifically, the content of this article will expand the information a lot more.

How to Input Variable in Python

So, before gong on further, below is the syntax for variable input as a start :

input();

Using the above syntax, first of all just create a pseudo code statement to design scenario for performing variable input in Python programming language. The above syntax can be exist in several type of form. The first one is the form without having any parameter at all. And the second one is the form with a parameter.

How to Input Variable using input method with empty parameter in Python

Basically, this example and also the execution of it has already exist in the previous article. It is the default form for retrieving input into a variable with just an empty parameter. It exist in the article in this link with the title of ‘How to Input in Python’. So, the following is the example directly without having to define the pseudo code in order to perform the input variable :

C:\>python
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> input_test = input();
56
>>> print(input_test);
56
>>>

As the execution of the above input method finish, it will display the content of the variable of ‘input_test’ after printing it with the ‘print’ command or statement.

How to Input Variable using input method with a parameter in Python

After the previous part where the input method is possible for performing execution to retrieve data input, this part will be the modification of it. Actually, it is just giving an additional argument as a parameter into the input method. Basically, it will very useful for giving an additional information about the input process. Below is the example of the execution process for retrieving the data input :

C:\>python
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> input_test = input('Please input any number : ');
Please input any number : 60
>>> print(input_test);
60
>>>

So, the above command execution with input method is only has a slight different with the previous one above. Only an additional parameter for describing or giving information about the input. It will just print a string to give information to the user about what to be input. Furthermore, the input data will be directly forwarded to the variable with the name ‘input_test’. It also available for further print process to display the data or the value inside the ‘input_test’ variable.

Leave a Reply