Python Print Statements with Explanations and Outputs
fruits = ["apple", "banana", "cherry"]
print(*fruits)
print(*fruits, sep=" | ")
Explanation: The * operator unpacks the list, printing each item separately. The sep parameter defines the
separator between values.
Output: apple banana cherry
Output: apple | banana | cherry
numberss = [1, 2, 3, 4]
print("Numbers:", numberss)
Explanation: The print function displays a string followed by a list. The list appears with its square brackets.
Output: Numbers: [1, 2, 3, 4]
print("{} is {} years old.".format("Bob", 25))
Explanation: The format() method inserts values into the curly braces in the string.
Output: Bob is 25 years old.
name = "Alice"
age = 30
print(f"{name} is {age} years old.")
Explanation: This uses an f-string for string interpolation, allowing variables to be embedded directly inside
the string.
Output: Alice is 30 years old.
print("Processing...", flush=True)
Explanation: The flush=True argument forces the output to be immediately written to the screen, useful in
real-time applications.
Output: Processing...
print("Loading", end="...")
print("Done!")
Explanation: The end parameter prevents a newline after the first print, making the second print continue on
the same line.
Output: Loading...Done!
print("Hello", "World", 2025)
Explanation: Multiple values can be printed in one statement, separated by spaces by default.
Output: Hello World 2025
print("Hello", "World", sep=", ")
Explanation: The sep parameter customizes the separator between printed items, here using a comma
followed by a space.
Output: Hello, World