W3docs

How can I print variable and string on same line in Python?

You can use the print() function in Python and use the + operator to concatenate a string and a variable.

You can use the print() function in Python and use the + operator to concatenate a string and a variable. For example:

Concatenate a string and a variable in Python using the + operator

python— editable, runs on the server

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

Alternatively, you can use the format() method to insert the value of a variable into a string, like this:

Concatenate a string and a variable in Python using the format method

python— editable, runs on the server

or use f-strings (Python 3.6+)

Concatenate a string and a variable in Python using the f-strings

python— editable, runs on the server

You can put all these examples in the same program and will run successfully.