DEV Community

hebaShakeel
hebaShakeel

Posted on

Literals in Python

Literal is a raw data given in a variable. There are various types of literals:

Numeric Literals

a = 0b1010 -> Binary literals
b = 100 -> Decimal literals
c = 0o1010 -> Octal literals
d = 0x1010 -> Hexadecimal literals
float_1 = 10.5
float_2 = 1.5e2 (1.5 * 10 to the power 2)
float_3 = 1.5e-3 (1.5 * 10 to the power -3)

String Literals

string = 'I am Heba'
strings = "I am Heba"

multiline = """This is a multiline string. """

Boolean Literals

a = True + 4
o/p = 5

b = False + 10
o/p = 10

Special Literals

a = None
This is useful when we want to declare a variable that doesn't have to be assigned a value at the moment.

Top comments (0)