print()
print("a", "b", 3)— separates values with a spacesep="-"— change the separatorend=""— don't move to a new lineprint()alone prints an empty linefile=sys.stderr— print errors to the error stream
input()
name = input("Your name: ") shows a prompt and waits for the user. It always returns a string.
Converting input
age = int(input("Age: "))price = float(input("Price: "))- Several values on one line:
a, b = map(int, input().split())
Handling bad input
If the user types abc, int() raises ValueError. Use a loop with try / except to ask again (see the Exceptions lesson).
Nice output
Use f-strings with alignment to print tables and receipts.
Example
Example — Simple bill calculator
Python
item = input("Item name: ")
price = float(input("Price: "))
qty = int(input("Quantity: "))
subtotal = price * qty
gst = subtotal * 0.18
print("-" * 30)
print(f"{'Item':<15}{item:>15}")
print(f"{'Subtotal':<15}{subtotal:>15.2f}")
print(f"{'GST 18%':<15}{gst:>15.2f}")
print(f"{'Total':<15}{subtotal + gst:>15.2f}")
print("-" * 30)
print("Thank", "you", sep="-", end="!\n")
Entering Pen, 20, 5 prints a neat receipt: Subtotal 100.00, GST 18% 18.00, Total 118.00, then Thank-you!