Skip to content

Print integer Python | Example code

  • by

To Print an integer in python simply pass the value in the print() function. It will output data from any Python program.

a = 10
print(a)

# addition
print(5 + 10)

Output:

10
15

How to print a string and an integer in Python

Use comma or string casting to print() a string and an integer.

a_str = "Hello"

an_int = 1

print(a_str, an_int)
print(a_str + str(an_int))

Output:

Print integer Python

Printing string and integer (or float) in the same line

A variable x=8 and needs output like “The number is 8” (in the same line).

Example code print the string “The number is” and the variable together.

a = 8
print("The number is", a)
# OR
b = 8
print("The number is " + str(b))

# Float
f = 14.08
print("The number is " + str(f))

Output:

The number is 8
The number is 8
The number is 14.08

Do comment if you have any doubts and suggestions on this Python integer (Number) topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *