Get answer of your all questions and doubts! ➤
Question
How many types of integer literals are allowed in python?
[Computer Science Class – 11 Sumita Arora solutions. Chapter 6 – Python Fundamentals.]
Answer
- 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).
Example – 1234, 41, +97 - Octal integer literals – A sequence of digits starting with 0o (digit zero followed by letter o) is taken to be an octal integer.
Example – decimal integer 8 will be written as 0o110 as octal integer. (8₁₀=10₈) - Hexadecimal integer literals – A sequence of digits preceded by 0x or 0X is taken to be an hexadecimal integer.
Example – 12 (decimal integer) will be written as 0o14 (as octal) and 0xC (as hexadecimal).