Python Datatypes: ================= Datatypes: 2-types: 1) Primitive Datatypes all fundamental datatypes Number type/Numerical type: integer, floating-point and complex data Non-numerical type: Boolean Datatype (True/False) Integer Literals: ================= ==> Pre-defined/inbuilt datatype every data representation is an object for one specific class. Ex: integer data ==> object ==> Int class ==> 4-ways: 1) Base-10/Decimal value : 0 to 9 ex: 1223, 1098 etc. no prefix is needed for decimal data 2) Base-8 / Octal Value : 0 to 7 prefixed with: 0O/0o ex: 0o1212 3) Base-2/Binary Value : 0 and 1, can always be prefixed with '0b' or '0B'. ex: 0B1100110 4) Base-16/Hexadecimal value: 0 to 9 and A to F can always prefix with '0X' or '0x' ex: 0x1122ff etc. # Decimal a = 100 b = 1993 # Octal c = 0O117722 d = 0o1765 # Binary e = 0b110011 # Hexadecimal f = 0X11ffe4 print(type(a)) print(type(b)) print(type(c)) print(type(d)) print(type(e)) print(type(f)) 2) Floating-point: ================== pre-defined class: "float" ==> an inbuilt datatype. ==> can be define in two ways: 1) using decimal point ======================== Note: we can always consider the decimal literals only for float data definition. Ex: 12.234, 0.1110022 etc. 2) using scientific notation ============================= exponential form ex: 12e-7, 0.5e9 # decimal point a = 0.9876 # exponential form b = 1.2e-7 c = 7E9 print(type(a)) print(type(b)) print(type(c)) 3) Complex Data: ================ ==> an inbuilt datatype a pre-defined class ==> complex ==> the combination of real data and imaginary data. Syntax: real +/- imaginary Note: ===== 1) real data ==> integer (decimal/binary, octal, hexadecimal) and float Ex: 12+13j, 0b11001 - 13j, 0o1762+14j, 0xaaf12 - 123j, 123.234+23j ==> correct 2) Imaginary data ==> Decimal and floats a = 12 + 23j b = 0b11001 - 24j c = 0o1723 + 25j d = 0Xaf123 - 97j # e = 21 - 0b11001j e = 21.34 - 31.24j print(type(a)) print(type(b)) print(type(c)) print(type(d)) print(type(e)) =============================================== Non-numerical type: =================== ==> Boolean can define with only two values {True, False} True ==> 1 False ==> 0 ==> An inbuilt datatype pre-defined class ==> "bool" a = True b = False print(type(a)) print(type(b)) print(a + a) # 2 print(a + b) # 1 =========================================== 2) Collection Datatypes ======================= ==> four types: 1) Sequential Datatypes String Datatype List Datatype Tuple Datatype 2) Non-Sequential Datatypes set datatype frozen set datatype 3) Mapping Type key : value Dictionary 4) Byte Type 0 to 255 bytes datatype bytearray datatype