int data type in Python

int data type:

we can use int data type to represent whole numbers(integral value)
Eg:
       a = 10
       type(a) #int

Note:

In Python2 we have long data type to represent very large integral values.
But in Python3 there is no long type explicitly and we can represent long value also using int type only.

We can represent int value in the following ways

  1. Decimal form
  2. Binary form
  3. Octal form
  4. Hexa decimal form

1. Decimal form(base-10):

It is the default number system in Python
The allowed digits are :0 to 9
Eg:  a = 10

2. Binary form(base-2):

The allowed digits are: 0 & 1
Literal value should be prefixed with 0b or 0B
Eg: a = 0b1111
      b = 0B1111

3.Octal form(base-8)

The allowed digits are:0 to 7
Literal value should be prefixed with 0o or 0O.
Eg: a = 0o123
      a = 0O544

4. Hexa decimal form(Base-16):

The allowed digits are: 0 to 9,a-f(both upper and lower case are allowed)
literal value should be prefixed with 0x or 0X
Eg:
       a =  0xFACE
      a = 0Xforce
     a = 0xFan

Note:

a=10
b=0o10
c=0x10
d=0B10
print(a) #10
print(b) #8
print(c) #16
print(d) #2

No comments:

Post a Comment

Featured Post

Core and Advance Python

                      Language Fundamentals