Q. How many ways are there in Python to represent an integer literal?


Answer =

Python allows three types of integer literals:

(a) Decimal (base 10) integer literals
(b) Octal (base 8) integer literals
(c) Hexadecimal (base 16) integer literals


(a) Decimal Integer Literals:- An integer literal consisting of a sequence of digits is taken to be decimal integer literal unless it begins with 0 (digit zero).
For instance, 1234, 41, +97, -17 are decimal integer literals.

(b) Octal Integer Literals:- A sequence of digits starting with 0 (digit zero) is taken to be an octal integer.
For instance, decimal integer 8 will be written as 010 is octal integer. (810 = 108,) and decimal integer 12 will be written as 014 as octal integer (1210 = 148).

(c) Hexadecimal Integer Literals:- A sequence of digits preceded by 0x or 0X is taken to be an hexadecimal integer.
For instance, decimal 12 will be written as 0XC as hexadecimal integer.
Thus number 12 will be written either as 12 (as decimal), 014 (as octal) and 0XC (as hexadecimal).

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post