PYTHON DATATYPES: ================== Datatype ==> Type of data ==> In how many forms the data in program we can define ==> Classified into two types: 1) Primitive Datatypes/Fundamental Datatypes 2) Non-Primitive Datatypes/Sequence Datatypes 1) Primitive Datatypes/Fundamental Datatypes ============================================ total 4-primitive datatypes: 1) Numerical type Integer : Built-in Class: int Float : float Complex : complex 2) Non-Numerical Boolean : bool type() Integer ======== class : int ==> four ways to define the int data: 1) Decimal Data ================ ==> any general number is a decimal ex: 123, 100, 10234 etc. ==> decimal ==> are always able to define with total 10-literals (0 to 9) ex: 12,34,56,789 ==> also called as "base-10" number 2) Binary Data ============== ==> always able to define with only two literals: 0 and 1 ==> also called as "base-2" number. ex: 10101, 100110 etc. ==> decimal ==> to define the binary, we should prefix number with "0b" or "0B". ex: 0b10101, 0B100110 ==> Binary 3) Octal Data ============== ==> always be define with total 8-literals (0 to 7) ==> can always prefix with: '0o' or '0O' ex: 120376, 117765 ==> decimal 0o120376, 0O117765 ==> octal 4) Hexadecimal Data ==================== ==> possible to define with digits and alphabets also. ==> the total of 16-characters we can use to define hexadecimal data 0 to 9 and a to f ==> also called as "base-16" number ==> also called as "alpha numeric" number. ==> can always prefix with '0x' or '0X'. ex: 0x1122, 0XAF123 etc. # decimal data representation a = 1993 b = 100 c = -123 # Binary data representation d = 0b11001 e = 0B10101 # binary f = 10011001 # decimal # g = 0B123 # print() ==> by default able to print only the decimals # Octal Data representation g = 0o1122 h = 0O1234 i = 1234 # Hexadecimal data representation j = 0Xaf1122 k = 0x1122 print(type(a)) print(type(b)) print(type(c)) print(type(d)) print(type(e)) print(type(g)) print(type(h)) print(type(j)) print(type(k)) print(d) print(e) print(f) print(g) print(h) print(i) ============================================= Base Conversions: ================== Decimal ==> binary binary ==> decimal etc. bin() oct() hex() Octal Table: =========== 0 ==> 000 1 ==> 001 2 ==> 010 3 ==> 011 4 ==> 100 5 ==> 101 6 ==> 110 7 ==> 111 Hexadecimal Table: ================== 0 ==> 0000 1 ==> 0001 2 ==> 0010 3 ==> 0011 4 ==> 0100 5 ==> 0101 6 ==> 0110 7 ==> 0111 8 ==> 1000 9 ==> 1001 a/A==> 10 ==> 1010 b/B==> 11 ==> 1011 c/C ==> 12 ==> 1100 d/D ==> 13 ==> 1101 e/E ==> 14 ==> 1110 f/F ==> 15 ==> 1111 bin() ===== # binary conversion # bin() ==> can convert any base value (10/8/16) into base-2 (binary) # Syntax: # bin(any base value) # decimal to binary a = 100 # decimal print(bin(a)) # Octal number to binary b = 0o121 print(bin(b)) # Hexadecimal to Binary c = 0x1212 print(bin(c)) ======================================= Assignment: ========== WAP to find the binary for given data: 1223 0o11223 0XAF179