Two built-in functions in Python are used to perform input and output operations (OI Operations). The two built-in functions for performing output and input operations are listed below.
To perform input operations, Python includes the function input(). The input() function can be used both with and without a message.
Syntax:
input('prompt')
where prompt is an optional string displayed on the string when taking input.
Example:
# Taking input from the user
name = input("Enter your Name: ")
print("Hello, " + name)
print(type(name))
Output:
Enter your Name: Rabecca Fatima
Hello, Rabecca Fatima
<class 'str'>
By default, Python treats all input as a string. To convert it to another data type, we must explicitly convert the input. To convert an int or a float, for example, use the int() and float() methods, respectively.
Example:
# Taking input from the user
Roll = int(input("Enter your Roll: "))
print( Roll)
print(type(Roll))
Output:
Enter your Roll: 20012
20012
<class 'int'>
The built-in function print( ) is used to output the given data to the standard output device (Screen). When we use the print() function to display a message, the string can be enclosed in single or double quotations.
Note: the return value of print( ) function is None.
Syntax:
print(value(s), sep= ‘ ‘, end = ‘\n’, file=file, flush=flush)
Parameters:
Example:
Roll = 102
print( "ROLL NUMBER :", Roll)
Output:
ROLL NUMBER : 102
We can implement the ‘%’ operator. % values are replaced with zero or more element values. % formatting is similar to ‘printf’ formatting in the C programming language.
Example:
# Taking input from the user
num = int(input("Enter a value: "))
multi = num *11
# Output
print("The product is %d" %multi)
Output:
Enter a value: 9
The product is 99
Note: also read about Modules and Functions in Python
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…