Pythondex

Tutorial

Printing Variables in Python

You can print variables to see their values or combine them with text messages. Python provides several ways to do this.

1. Using Commas

Commas automatically add a space between items:

2. Using String Concatenation (+)

You can join strings using the + operator, but you must convert non-strings to strings:

3. Using f-Strings (Recommended)

f-Strings allow embedding variables directly in the string:

4. Combining Multiple Variables

You can mix text and multiple variables easily with f-strings: