Python import, input and output function; Through this tutorial, i am going to show you what is import, input and output functions in python.
Python (I/O) input, output function and import keyword
Let’s explain these input, output functions and import keyword:
Output (Print()) function python
In the python programming, print function is used to display data as output.
Syntax of print function
Print('any text');
Example of output (Print()) function
print('This is output example')
Input (Input()) function in python
In the python programming, input() function is used to take some input by user.
Till now you are not getting any value input from the user. In the upper example and had to insert hard code values in the print function. Now you will tell you how to do the input function. How to take value from end-user
Syntax of input() function
input([prompt])
Here, prompt is the string you wish to display on the screen. It is optional.
Example of input function
num = input('Enter a number: ') print(num)
When you run this program you will see a prompt, waiting for you to give input. It will take as many characters as you type until Enter is pressed.
Python Import
The python import keyword, which is used to import the prebuild module or another module in your python program.
Example of import keyword
For example, you can import the math module by typing in import math.
import math print(math.pi)
Example 2 – import keyword with input
Here you will create a program to calculate squart root of any number in python:
from math import sqrt var = int(input("Enter a Number: ")) sqt = sqrt(var) print(sqt)
In this example, you have calculated the square root of the user input number by math function sqrt(). So you have imported sqrt() function from the math module in our python program.