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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…