Learning Python Part-11: Python Literals

Literal in Python, is a raw data that is passed on to a variable or constant as values. 

In Python programming language, there are various types of literals as listed below:

  • Numeric Literals:
    • Numeric Literals are immutable (unchangeable). 
    • Numeric literals can belong to different numerical types like Integer, Float, and Complex.
    • Examples:

  • String literals:
    • A string literal is a sequence of characters surrounded by quotes.
    • String literals are immutable (unchangeable).
    • We can use both single, double or triple quotes for a string. 
    • A character literal is a single character surrounded by single or double quotes.
    • Examples:

  • Boolean literals:
    • A Boolean literal can have any of the two values: True or False
    • Examples:

  • Special literals:
    • Python contains one special literal i.e. None. 
    • We use it to specify to that field that is not created.
    • Examples:

  • Literal Collections:
    • There are four different literal collections List literals, Tuple literals, Dictliterals, and Set literals.
    • Examples:
I will talk about each of these literals with more details in upcoming posts. 

Leave a Reply