How does the print() function handle multiple values?

QuestionsQuestions8 SkillsProYour First Python LabSep, 17 2025
0154

The print() function in Python can handle multiple values by accepting them as separate arguments, which are then printed to the output. The values are separated by a space by default, but you can customize the separator using the sep parameter. Additionally, you can control the end character using the end parameter.

Here’s an example:

# Printing multiple values
print("Hello", "world", 2023)

# Custom separator
print("Hello", "world", 2023, sep=", ")

# Custom end character
print("Hello", end=" ")
print("world!")

Output:

Hello world 2023
Hello, world, 2023
Hello world!

In this example, the first print() outputs the values with a space, the second uses a comma as a separator, and the third modifies the end character to a space instead of the default newline.

0 Comments

no data
Be the first to share your comment!