Python Programming – Literals

You can learn about Introduction to Python Programming Programs with Outputs helped you to understand the language better.

Python Programming – Literals


Literals can be defined as data that is given in a variable or constant. For example 7, -2.9, “XYZ”, ‘Hello’ are literals. Literals are fixed numeric or non-numeric values. Python supports the following literals:

String Literals

Strings are the only literal sequence type that contains, a sequence of characters. However, characters are not a type. So strings are the lowest-level primitive for character storage and manipulation. String literals are formed by enclosing text in the single or double or both a single and double quote. For example, “Abhishek”, ‘3784’, ‘Some “quoted” \’extra\’ text.’.

A string literal can also span multiple lines. It can also be enclosed in matching groups of three single or double quotes (generally referred to as triple-quoted string). For example,
” ” ” This string
spans several lines
because it is a little long.
” ” ”

Numeric Literals

Python supports three types of numeric literals inte-ger, float and complex. For example,
a = 7 #Integer literal
b = 25.7 #Float Literal
x = 3.14j #Complex Literal

Python Programming – Introduction to Programming chapter 2 img 56

Boolean Literals

Boolean literals are used to denote boolean values. They contain either True or False.
isboolean = True # Boolean literal

Leave a Reply

Your email address will not be published.