Skip to main content
Anime study buddy

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

Variable vs literal

  • Variable: name that stores a value
  • Literal: fixed value written directly in code
x = 25
Here:
  • x is variable
  • 25 is literal

Types of literals

Numeric literals

a = 10      # int literal
b = 3.14    # float literal
c = 2+5j    # complex literal

String literals

name = "Dhruv"
city = 'Delhi'

Boolean literals

is_valid = True
is_empty = False

Special literal

data = None
None means no value / null reference.

Escape sequences in strings

print("Hello\nWorld")
print("Name:\tDhruv")
print("She said: \"Python\"")
Useful sequences: \n, \t, \", \\

Exam-focused points

  • literals are constants directly written in source code
  • True, False, and None are keywords
  • string literals can use single or double quotes

Practice questions

  1. Classify these as variable or literal: x, 99, "hi", False.
  2. Write one example each of int, float, bool, and None literal.
  3. Print this exact output using escape sequences:
Name: Dhruv
Branch: CSE