In Python's print() function, you cannot directly use multiple different separators between items in a single call. The sep parameter allows you to specify only one separator for all items being printed. However, you can achieve the effect of multiple separators by using string concatenation or formatting techniques.
Workaround Examples
Here are a few methods to simulate multiple separators:
-
Using Concatenation:
You can manually concatenate strings with different separators:print("Apple" + ", " + "Banana" + " - " + "Cherry")Output:
Apple, Banana - Cherry -
Using f-strings:
You can format the output using f-strings for more complex scenarios:fruit1 = "Apple" fruit2 = "Banana" fruit3 = "Cherry" print(f"{fruit1}, {fruit2} - {fruit3}")Output:
Apple, Banana - Cherry -
Using a List and Join:
If you have a list of items and want to use different separators, you can join them with a single separator and then concatenate:fruits = ["Apple", "Banana", "Cherry"] print(", ".join(fruits[:-1]) + " - " + fruits[-1])Output:
Apple, Banana - Cherry
Summary
While you can't specify multiple separators directly in the print() function, you can use string manipulation techniques to achieve the desired output format. If you have any further questions or need more examples, feel free to ask!
