• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Print Multiple Variables in Python

Print Multiple Variables in Python

February 26, 2022 Leave a Comment

In Python, we can print multiple variables easily with the print() function. Just pass each variable to print() separated by commas to print multiple variables on one line.

x = 0
y = 1
z = 2

print(x,y,z)

#Output:
0 1 2

In Python, when writing programs, being able to check the value of certain variables can be useful.

Many times, when we want to check the value of a variable, printing it to the console is the easiest way.

We can print one variable, or print multiple variables, to the console using print().

To print multiple variables in Python, you just need to call print() and separate the variables by commas.

Below is a simple example of how to print multiple more than one variable to the console in a Python program.

x = 0
y = 1
z = 2

print(x,y,z)

#Output:
0 1 2

The rest of this article goes into some other cases where you can output the value of multiple variables to the console.

Printing Multiple Variables to the Console with f-strings in Python

Python f-strings, or formatted string literals, were introduced in Python 3.6. f-strings make it incredibly easy to insert variables into other strings.

We can use f-strings to be able to easily print multiple variables to the console with Python.

Below is a simple example of how to use f-strings with print() to output multiple variables in Python.

fruit = "apple"
num = 3

print(f"We have {num} {fruit}s.")

#Output:
We have 3 fruits

Using format() to Print Multiple Variables to the Console in Python

You can also use the string format() function to print more than one variable to the console.

With the format() function, we just need to put curly brackets in a string we want to insert variables. The downside of using format() is that we need to be precise with the order of the variables we pass.

Below is a simple example of how to use format() with print() to print more than one variable in Python.

fruit = "apple"
num = 3

print("We have {} {}s.".format(num, fruit))

#Output:
We have 3 fruits

Printing More than One Variable to Console with Concatenation

The final way to print more than one variable to the console in Python is with concatenation. If you have all string variables, this is very straightforward.

Below is an example in Python of using string concatenation to output more than one variable to the console in Python.

fruit = "apple"
print("We have " + fruit + "s.")

#Output:
We have apples.

If you have numeric variables, then you need to convert those variables to strings to use with concatenation.

Below is an example in Python of using concatenation to print multiple numeric variables in Python.

fruit = "apple"
num = 3

print("We have " + str(num) + " " + fruit + "s.")

#Output:
We have 3 fruits

Hopefully this article has been useful for you to understand how to print multiple variables using Python.

Other Articles You'll Also Like:

  • 1.  How to Concatenate Tuples in Python
  • 2.  How to Group By Columns and Find Mean in pandas DataFrame
  • 3.  Change Python Turtle Background Color with screensize() Function
  • 4.  Python Check if Object is Iterable with hasattr() Function
  • 5.  Using Python to Convert Timestamp to Date
  • 6.  What Curly Brackets Used for in Python
  • 7.  Sort a List of Strings Using Python
  • 8.  Write Variable to File Using Python
  • 9.  Using Python to Compare Strings Alphabetically
  • 10.  Create List of Odd Numbers in Range with Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy