Python Input Output (I/O) Functions & Import Keyword

Here, we have discussed about the python input, output and import operations. We have learnt how to use the print(), input() functions and import....

In this article we will going to discuss about the Python input, output and import operations. Here, we will know how to use the print(), input() functions and import keyword. 

Python Input Output (I/O) Functions & Import Keyword

Python Input 

In order to get the value from the program then you can use the function. When a user input a value with the help of then it is treated as a string. The syntax of input() is as follows;

input([prompt])

Here, prompt is the optional string that we want to display in our screen.

name = input("Enter your first name: ") print("Welcome to Answersjet" + name) print(type(name))

Output

Enter your first name: Deepak

Welcome to Answersjet, Deepak

<class 'str'>

Python Output

To show output on screen in python programming language, we use the function. Simply, the function is used to show the output data of strings and variables.

Python Output Example 1;

print('Welcome to Answersjet.com')

Output

Welcome to Answersjet.com

Python Output Example 2;

name = 'Programming Language' print('Python is a', name)

Output

Python is a Programming Language

In the above example, to print two different statements we can see that we have used the end keyword which defaults to print a new line.

String Formatting 

There is a special function in python which is used to make the output look more attractive and use to give us more flexibility over the output, it is known as Format function which is used by method.

We use the {} Curly brackets as placeholders to hold the variables and strings in place.

Python String Formatting Example;

print("I love {0} and {1}".format("my India","Indian People"))

print("All Indians are my {0} and {1}".format("Brother","Sisters"))

Output

I love my India and Indian People

All Indians are my Brother and Sisters


Python Import

To import a function or a definition from the module, keyword is used. A module refers to a file which contains functions, definitions and statements. 

Python Import Example;

import math

print(math.pi)

Output

3.141592653589793


Conclusion

Above we have discussed about the python input, output and import operations. We have learnt how to use the print(), input() functions and import keyword. In order to get the value from the program then you can use the input() function. To show output on screen in python Programming Language, we use the print() function. To import a function or a definition from the module, import keyword is used.