Learning outcomes
By the end of this chapter, you should be able to:- define literal and variable clearly
- identify numeric, string, boolean, and special literals
- write valid escape sequences in strings
30-minute recording plan
0-7 min: variable vs literal concept7-15 min: numeric, string, boolean, andNoneliterals15-22 min: escape sequences and raw strings22-27 min: mini coding example27-30 min: exam-focused summary
Quick idea
- Variable = container name/reference
- Literal = actual fixed value written in code
- Program statements usually contain both together
Variable vs literal
- Variable: name that stores a value
- Literal: fixed value written directly in code
xis variable25is literal
Types of literals
Numeric literals
String literals
Boolean literals
Special literal
None means no value / null reference.
Escape sequences in strings
Escape sequence means a backslash-based code inside a string. It is used when normal typing cannot represent formatting/special characters directly.\n: new line\t: horizontal tab space\": include"inside a double-quoted string\\: print one backslash character
Mini showcase: invoice line formatter
Exam-focused points
- literals are constants directly written in source code
True,False, andNoneare keywords- string literals can use single or double quotes
Practice questions
- Classify these as variable or literal:
x,99,"hi",False. - Write one example each of int, float, bool, and None literal.
- Print this exact output using escape sequences:
