Thursday, October 23, 2025
HomeLanguagesPython (I/O) Input Output and Import Example

Python (I/O) Input Output and Import Example

In this python input, output function and import example tutorial, we are going to explain daily useful inbuilt functions in python.

Basically, you are familiar with these Python print function. Because we have already use the print() function in the previous python for displaying data as output in python programs.

But so far we have not used the input () function and import keyword in our previous Python tutorial. In this tutorial, we will explain how to import Python modules using the import keyword and how to use them.

And along with this, we will also show how to input value from the user using the input () function.

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')

.box-4-multi-260{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:15px!important;margin-left:auto!important;margin-right:auto!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:250px;padding:0;text-align:center!important;width:100%}

Input (Input()) function in python

In the python programming, input() function is used to take some input by user.

Till now we were not getting any value input from the user. In the upper example, we had to insert hard code values in the print function. Now we 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 we 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, we can import the math module by typing in import math.

import math
print(math.pi)

Example 2 – import keyword with input

Here we will create a program to calculate squart root of any number in python:

.banner-1-multi-360{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:15px!important;margin-left:auto!important;margin-right:auto!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:250px;padding:0;text-align:center!important;width:100%}

from math import sqrt
var = int(input("Enter a Number: "))
sqt = sqrt(var)
print(sqt)

In this example, we have calculated the square root of the user input number by math function sqrt(). So We have imported sqrt() function from the math module in our python program.

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS