Python Program to Print Integer (With Example)

In this article, we will go through python program to print integer with example.

Tutorialwing Python Program to Print Integer Example

Above image clearly depicts how any value is read and printed from/to console.

At first, we entered some value to console. Then, it is read using some built-in methods. After that, value is stored in some variable. Then, stored value is printed to console using built-in methods.

Using print() and sys.stdout.write() method we can print integer variable to console.

Method 1: Using print() method

Syntax

print(SOME_VALUE)

Here, SOME_VALUE is integer value/variable. However, it can also be string, float etc.

Program 1

a = input("Enter a number:")
print("Entered number is: ", a)

When we run above program, we will get output as below –

Enter a number:
12
Entered number is:  12

In above program, user is asked to enter a number with message “Enter a number”. Then, value entered by user is stored to variable a . After that value stored in variable a is printed to console by using print() function in python.

Method 2: Using sys.stdout.write() method

We can print output to console using method present in sys module in python. There is a method sys.stdout.write() method present inside sys module in python that can be used to print output.

syntax

sys.stdout.write(SOME_VALUE)

Program 1

import sys

a = input("Enter a number:")

sys.stdout.write("Entered number is: " + a)

Here, we are using write() method to print value in python. This method is present inside sys module in python. It accepts text as argument and prints it. it does not move to next line after printing value. If you want to move to next line after printing value, you need to use “/n”.

When you run above program, output will be –

Enter a number:
76
Entered number is: 76

Here, we have printed value stored in variable a using sys.stdout.write() method.

That’s how we can write python program to print integer.

Leave a Reply