Write a short note on literals in Python.

 

Answer:

Literals are data items that have a fixed value. 

Python has the following 4 literals:

 

1. String literals : the text enclosed in quotes  (single or double) is considered to be a string  literal.

Examples:

  • “abc”
  • ‘d’
  • “123start”

2. Numeric literals: Numeric literals can be of type int, float or complex.

Examples:

  • 10
  • 3.1497
  • 2+3i

3. Boolean literals: It represents one of  the two Boolean values.

Examples:

  • True
  • False

 4. Special literals: None is a special literal that  indicates absence of a value and is generally  used to indicate end of lists in python. It  means that there is no useful information.

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.