All discussions
enpython

How does the print() function work with multiple arguments?

4mo·Aarav SharmaLvl 4

I saw someone use print("Name:", name, "Age:", age) and it printed everything separated by spaces. How does Python know to add spaces? Can I change the separator?

1 replies

1 replies

P
Priya PatelLvl 4·4moBest

Great question! The print() function in Python has a sep parameter that defaults to a space. So print("a", "b") outputs "a b". You can change it: print("a", "b", sep="-") outputs "a-b". There's also an end parameter that controls what's printed at the end (default is newline).

6