Input And Output In Python Programming Language

Let’s discuss how to perform input and output operations in Python I will start with the input let’s discuss how it works in order to take input from the user Python provides input function so the syntax is input and within double quotes you can write down the message for example enter number enter our number and when you will use.

This function it will prompt message to the user to input something so whatever the input that user will provide that will.

Be transferred to num1 all right so let’s execute it and you can see that it is now asking with this prompt enter our number so I am going to supply a number for example 20 and press Enter now the.
Input has been passed on to num1 now if you will try to perform some.

Addition operation on num1 it won’t be allowed because the type of num1 is a string actually the value which is stored in num1 is of string type so if you wish to perform some operation on num1 for example number 1.

Plus 20 it won’t be allowed because num1 is a string type if you wish to automatically evaluate the input which is being given by the user use e well function it will automatically evaluate the type of input to its respective type for example for example I.

Am going to use another variable and through this variable we will pass a number but this number whatever input that user will give in the numeric form will be treated as strain right so we need to evaluate it to its respective type if.

It is of string type it will be treated as string if it is a number then it will be treated as a number.

So now if I execute this statement the input that we will provide will be treated as number input so now if I perform some arithmetic operation on this number on the value which it which enum two points two can be used as can be used for the arithmetic operation so num to contain 20 and I added 20 to it which.

Has evaluated to 40 so eval function will automatically evaluate the input that you have supplied to the function and it will be then converted to its respective type and will be.

Transferred to num2 so this is how you can take input from the user now let’s discuss how you can print values of the variable with some function which is provided by the Python and it is print function so though you can print value like this it is allowed but when you are going to work on your real programs then you will require a function to format your outputs right so for that purpose.

We have got a function called print you can print messages like the simple message so it is the simple message and if you want to print the value of num to what you can do.

Can type the variable name and you can get the.