DATATYPES: ========== INTEGER DATA: ============ class: int Base Conversions: ================= 1) bin() ==> used to convert any base value of integer (decimal, octal and hexadecimal) to binary. 2) oct() ======== Inbuilt method used to convert any base value of an integer (Decimal/Binary/Hexadecimal) into Octal value. Syntax: oct(any value) a = 1234 # decimal value b = 0b1101101 # binary c = 0xa1f7 # hexadecimal print(oct(a)) print(oct(b)) print(oct(c)) ============================== 3) hex() ======= An inbuilt method belonging to inbuilt class of "int" ==> used to convert any base value of an integer (binary/decimal/octal) into hexadecimal. Syntax: hex(any value) a = 1234 # decimal value b = 0b11011001100011 # binary c = 0o1277 # octal print(hex(a)) print(hex(b)) print(hex(c)) ====================================== Decimal Conversion: =================== print() ==> will print any base value into decimal automatically. a = 0B1101101 # binary b = 0o12 # octal c = 0xaf # hexadecimal print(a) print(b) print(c) ======================================== FLOAT DATATYPE ============== INBUILT DATATYPE PRE-DEFINED CLASS: float type() ==> float data can also be represented in scientific form/exponential form. Ex: 12e5 or 12E-7 when we need to define too larger value/too smaller value ==> exponential form of the data ==> Exponential format is need to make reserve the data with less memory. Ex: 10000000000000000000000000 ==> 1 X 10^25 ==> 1 X 100/100 X 10^25 ==> 0.01 X 10^27 ==> 0.01E27 0.000000000000000000000001 ==> 1 X 10^-24 ==> 1/100 X 100 X 10^-24 ==> 0.01 X 10^-22 ==> 0.01e-22 NOTE: ==== 1) BINARY ==> NOT USED TO REPRESENT A FLOAT EX: 0B1101.110 ==> SYNTAX ERROR 2) OCTAL ==> NOT USED TO REPRESENT FLOAT EX: 0O1122.1122 ==> SYNTAX ERROR 3) HEXADECIMAL ==> NOT USED FOR FLOAT REPRESENTATION EX: 0XAF12.12AF ==> ATTRIBUTE ERROR Note: ===== bin(), oct() and hex() ==> not possible to convert a float into binary/octal/hexadecimal. ==> Type Error a = 123.234 b = -12.432 c = 0.000797 d = 1e27 e = 1E-27 # f = 0b1101.001 # g = 0o1122.2233 # h = 0xaf12.af23 print(type(a)) print(type(b)) print(type(c)) print(type(d)) print(type(e)) # print(bin(a)) # print(oct(a)) # print(hex(a)) ========================================================== COMPLEX DATATYPE: ================= ==> combination of real data and imaginary data. ==> real data can be allowed to define with: binary octal hexadecimal decimal float ==> imaginary value in python, must be suffixed with 'j' imaginary data can be allowed to define with only: decimal and float Syntax: real_data +/- imaginary_dataj Ex: 12 + 10j, 1.2 - 23.3j etc. ==> An inbuilt datatype pre-defined class: complex type() Note: ==== 1) If an imaginary number with: binary ==> syntax error octal ==> syntax error hexadecimal ==> syntax error a = 0b1101 + 10j b = 0o1723 - 1.2j c = 0xaf112 + 100j d = 123 - 12.34j e = 123.345 + 112j print(type(a)) print(type(b)) print(type(c)) print(type(d)) print(type(e)) print(a) print(b) print(c) print(d) print(e)