input() and print() functions of Python programming
input() and print() functions of Python:
Every computer program has to communicate with the outside world. To this purpose every programming language has special input and output functionalities. You have need to understand. Python programming provides numerous built-in functions. That are ready available to you at the Python programming . input() and print() are widely used for standard input and output operations respectively.
input() function:
The input() function is used to read input from the keyboard. If the input function is called, the program flow will be stopped until the user has enter an input and has ended the input with the return key. The text of the optional parameter, that is the prompt, will be printed on the screen. The input of the user will be interpreted. If the user puts in an integer value, the input function returns this integer value. If the user on the other hand inputs a tuple, the input function will return a tuple.
For Example: Writ e program to demonstrate use of input() function.
# This is example of input() function
str1 = input("Enter your First Name: ")
str2 = input("Enter your Last Name: ")
print("Your name is: ", str1)
print("Your name is: ", str2)
Output:
print() function:
This function is used to prints the given object to the standard output device (screen) or to the text stream file. The print() function is always used for display output on screen.
Syntax:
print(“String is here”)
For Example: Write a program to demonstrate the use of print() function.
# This is example of print() function
rollno=input("Roll No of Student:")
sname = input("Enter Name of Student: ")
sclass = input("Enter Class of Student: ")
scity = input("Enter City of Student:")
mno = input("Enter Mobile Number:")
print("...................................................")
print("--------Student Details----------")
print("...................................................")
print("Roll No : ", rollno)
print("Name : ", sname)
print("Class : ", sclass)
print("City : ", scity)
print("Mobile No. : ", mno)
Output:
Output formatting in python:
Programmer have need to format our output to make it look attractive as per yours needs. This time you use .format() method. This method is visible to any string object in python programming. Curly braces {} are used as placeholders. We can specify the order in which it is printed by using index.
For Example: Write the demonstrate the use of print formatting.
#program for formatting output in python
print('This is my Name: {0} {1}'.format('Jaypal','Shinde'))
print('This is my Name: {1} {0}'.format('Jaypal','Shinde'))
Output:



Comments
Post a Comment