Talking to the user: print with sep and end, prompts that make input() friendly, and the backslash codes \n and \t that shape output.
01
Learning objectives
Print multiple values in one call and control the separator with sep.
Suppress or replace the automatic newline using end.
Write input() with a clear prompt and cast the result in the same line.
Use the escape sequences \n, \t, \\ and \" inside strings.
Format a small receipt/table of output using \n and \t.
02
Lesson notes
print() is the first function every Python programmer meets, and it is more configurable than it looks. Pass several values separated by commas and print outputs them in order with a single space between each — print("Marks:", 88) gives Marks: 88. The space is just the default value of the sep (separator) parameter: print("A", "B", sep="-") gives A-B, and sep="" glues values with nothing between them. sep answers 'what goes BETWEEN my values?' and is a favourite 2-mark question.
The other default worth mastering: print finishes each call by moving to a new line. That newline is the value of the end parameter — by default end="\n". Override it and consecutive prints share a line: print(1, end=" "); print(2) outputs 1 2 instead of stacking them. Building progress bars, rows of a pattern and comma-separated lines all use end; the pattern-printing challenges in the Labs lean on it heavily.
input() pauses the program and waits for the user to type a line and press Enter. Its one optional argument is the prompt — the text shown to the user before they type: name = input("Your name: "). Without a prompt the program sits there silently, which feels broken to the person using it, so professional code always prompts. Remember lesson 2.2b: whatever arrives comes back as a str, so numbers arrive pre-quoted and the cast belongs on the same line: age = int(input("Age: ")).
Some characters cannot be typed directly into a string — a newline, a tab, a quote that would end the string early. Escape sequences solve this: a backslash tells Python 'the next character is special'. The working set: \n newline, \t tab, \\ a literal backslash, \" a double quote inside a double-quoted string, and \' similarly for single quotes. print("Name:\tAyesha\nRoll:\t41") prints two tab-aligned lines. Escape sequences are how one print can lay out a whole receipt.
Output design is examinable: 'Write a program that reads two numbers and prints their sum, formatted as ...' appears in every past paper. The recipe is always the same — prompt, read, cast, compute, print with a labelled message. Keep labels human (Total = 50, not 50), align columns with \t, and build multi-line blocks with \n before resorting to extra print calls. The next lessons give you f-strings, which make all of this even cleaner — but sep, end and escapes remain the fundamentals underneath.
03
Worked code examples
sep and end — the two dials of print
Default sep is one space and default end is a newline. sep="-" replaces the between-values text; end="... " replaces the newline, so the next print continues on the same line.
print("A", "B", "C") # default sep and end
print("A", "B", "C", sep="-") # custom separator
print("Loading", end="... ") # no newline
print("done") # continues the line
Output
A B C
A-B-C
Loading... done
Input, cast in one line
The program is fed Ayesha, then 17. In a real terminal you would add a prompt inside input() — input("Your name: ") — so the user knows what to type. age is cast with int() immediately, so age + 1 does real arithmetic: 18, not "171".
name = input()
age = int(input())
print("Salam,", name + "!")
print("Next year you will be", age + 1)
Output
Salam, Ayesha!
Next year you will be 18
Escape sequences build a formatted receipt
\t jumps to the next tab stop, aligning the columns; \n (not needed here — print adds one) would break lines; \" places quote marks inside the double-quoted string.