Python Input and Output | How to take input and give output in python

Python Input and Output

python input output


In this article, we learn how to take input from the user using the input() function and how to give output using the print() function.


Python Output

To print output we use the print() function that was an in-built function in python.

Example 1:

print("Welcome to Docodehere")

Output:

Welcome to Docodehere

Example 2:

num = 1
print("Value of the num is: ",num)

Output:

Value of the num is:  1

Note:

  • When we want to print strings then use "" double inverted comma.
  • And when you want to use to print two different things then you want to use a comma to separate them that example was given in the above example2.
  • And to the print number you want to use nothings eg: print(1,2,3).


Output Using formating

We use formatting to print the output attractive and more affecting. Formatting is done by the str.format() method.

Example1:

a = 15b = 5
print('The value of a is: {} and b: is {}'.format(a,b))

Output:

The value of a is: 15 and b: is 5

Example2:

print('I am {0} and study in class {1}'.format('Ankur','12'))

Output:

I am Ankur and study in class 12

Example3:

print('Hello {name}{welcome}'.format(welcome = 'Goodmorning'name = 'John'))

Output:

Hello John, Goodmorning

Example4:

x = 16.216358
print('The value of x is %3.2f' %x)
print('The value of x is %3.4f' %x)

Output:

The value of x is 16.22
The value of x is 16.2164


Python Input

We take input from the user using the input() function and that is also an in-built function of python.

Example:

n = int(input("Enter any number: "))
print("The number is"n)

Output:

Enter any number10
The number is 10



Next Post Previous Post
No Comment
Add Comment
comment url