DEV Community

Lalit Kumar
Lalit Kumar

Posted on

Python print on same line without space

This Python tutorial is on how to print string and int in the same line in Python. This is a very common scenario when you need to print string and int value in the same line in Python.

How to print string and int in the same line in python?

Printing string and integer value in the same line mean that you are trying to concatenate int value with strings.

Some examples:


Hey the value of variable a is 452
You just entered 845

Here we will see how to concatenate string and int in Python.

In general, if you run this below Python code:

a = 5
print ("the value of a is" + a)

You will get an error like this:
TypeError: can only concatenate str (not “int”) to str

Do you know why you are getting an error like this?

Because you are trying to concatenate an integer value with a string using + operator. In Python, the + operator can only concertante strings as Python is a strongly typed programming language.

In order to solve this problem and to achieve our goal to concatenate strings with int we can use these below methods:
Read more

Top comments (0)