According to the mathematics four number systems are available they are -
1. Binary number system - The base (or) radix of the binary system is '2'. The possible digits that are used in binary number system are 0 and 1. We can give the binary number system number as a input by giving 0b beginning of number.
Example -
- i=0b1010; print i; 10
- j=0b1020; // It gives error message (because binary number only accepts)
2. Octal number system - The base / radix of the octal number system is '8'. The possible digits that are used in octal number system are 0,1,......7. We can give the input value in the form of octal number system format by giving '0' beginning of the number.
Example -
- x=0123; print x ; 83
- y=0182; // Error
3. Decimal number system - The base / radix of the decimal number system is 10. The possible digits that are used in decimal number system are 0,1,2,....9. The default number system followed by python is decimal number system.
Example -
- x=1234; print x; 1234
- y=124p3; // Error because of p
4. Hexadecimal number system - The base / radix of the hexadecimal number system is 16. The possible digits used in hexadecimal number system are 0,1,2,....9,a,b,....f. We can give the hexadecimal system as input by giving '0x' beginning of the number.
Example -
- p=0x25; print p; 37
- x=0x47j2; // Error
- q=0x2c; print q; 44
Note : we can give any number system number as input but output can be given in the form of decimal number system format.
bin() - It is used to convert any number system number to binary format / binary number system.
Example -
x=0b1010
print bin(x)
y=0123
print bin(y)
z=1234
print bin(z)
p=0x25
print bin(p)
Output -
0b1010
0b1010011
0b10011010010
0b100101
oct() - It is used to convert any number system number to octal number system format.
Example -
x=0b1010
print oct(x)
y=0123
print oct(y)
z=1234
print oct(z)
p=0x25
print oct(p)
Output -
012
0123
02322
045
hex() - It is used to convert any number system to hexadecimal number system format.
Example -
x=0b1010
print hex(x)
y=0123
print hex(y)
z=1234
print hex(z)
p=0x25
print hex(p)
Output -
0xa
0x53
0x4d2
0x25
Note - Non-decimal point numerical values we can represent in the form of any number system format but decimal point numerical values we can represent in the form of decimal number system format only.
x=0b1010.1010 //Error
y=0x234.234 // Error
Note -
1. All fundamental datatypes represents the objects are immutable objects.
2. Immutable means once if we create the one object with some content later we can't modify the content of that object.
3. If we try to modify the content of the immutable objects without modifying the content of those objects it will create either new object (or) it will give error message.
4. If 2 fundamental datatypes represented variables are assigned with some data then internally those variables points the same object.
Example
i=1234
print i
print id(i)
j=1234
print j
print id(j)
Output -
1234
12876884
1234
12876884
No comments:
Post a Comment