Python Output Variables

3 min read ·

In Python, variables are displayed using the print() function. You can output single variables, multiple variables, or combine variables with text.

Output a Variable

You can print the value of a variable directly using print().

Output Multiple Variables (Using Comma)

The recommended way to output multiple variables is by separating them with commas. This works even when variables have different data types.

Using + Operator with Variables

The + operator works only when variables are of the same type.

String + String (Allowed)


Number + Number (Allowed)


String + Number (Not Allowed)

Combining a string and a number using + causes an error.

Correct Way to Mix Text and Numbers

Using Comma (Best and Simple)


Using str() Conversion


Using f-strings (Modern & Recommended)


Practice

Learn Python Python Output Variables | Python Course