NONE DATATYPE ============== None ==> keyword in python ==> when we want to define a variable with nothing Syntax: name of the data = None a = None print(id(a)) print(a) =================================== TYPE CASTING ============= ==> ALSO CALLED AS "TYPE CONVERSION" ==> WHEN WE WANT TO CONVERT A DATA FROM ONE FORM TO ANOTHER FORM ==> TYPE CONVERSION IS USED. ==> THE INBUILT METHODS FOR TYPE CASTING ARE: int() float() complex() bool() str() int() === ==> when we need to convert any data/value into decimal, int() is used. Syntax: int(the value) Rules: ===== 1) any base value of an integer, can be converted into decimal. 2) any float value, can be allowed for the decimal conversion Ex: int(0.0097) ==> 0 int(0.98e-2) 3) No complex value can be converted into decimal. Note: int(complex) ==> Type Error 4) Boolean values (True,False) are considered for the decimal conversion. 5) Not all the string objects are allowed for decimal conversions. If string with numerals (integer(decimal)) ==> '1234' ==> possible for decimal conversion If string with non-numerals ==> not possible Ex: "12.23", "abcd" ==> not allowed. ==> Value Error. a = 0b11001 b = 0o112276 c = 0x1122ff d = 0.00879 e = 1.23e-7 # f = 12-23j f = True g = False h = '1234' # i = '12.32' i = 'abcd' print("To Decimal Conversion from any base value : ") print(int(a)) print(int(b)) print(int(c)) print("To Decimal Conversion from any Float Number:") print(int(d)) print(int(e)) # print(int(f)) print("The Decimla Conversion from Boolean:") print(int(f)) print(int(g)) print("String to Decimals:") print(int(h)) # print(int(i)) ======================================== float() ==== ==> used to convert any data/value to float data Syntax: float(data) Rules: ===== 1) Any Integer data (includes: binary, octal, hexadecimal and decimal) allowed for float conversion. 2) No complex value is allowed for the float conversion. ==> Type Error 3) Boolean values are possible to float conversion. 4) when a string with any decimal and with any float is allowed for the float conversion If string with alphabets and other special characters ==> Value Error # Any Integer to Float Conversion print(float(9876)) print(float(0b110001)) # binary ==> decimal ==> float print(float(0o1122)) # octal ==> decimal ==> float print(float(0x1122)) # hexadecimal ==> decimal ==> float # complex to float conversion # print(float(10+20j)) # Boolean to float conversion print(float(True)) # boolean ==> decimal ==> float print(float(False)) # string to float conversion print(float('123')) print(float('111.123')) # print(float('0b11001')) ====================================================== complex() ======== ==> used to convert any data to complex number Syntax: ====== 1) with single parameter complex(value) Here: (+/-)value is the parameter ==> is understood as "real data" by default Imaginary ==> 0j ex: complex(10) ==> 10 + 0j 2) with two parameters complex(val1,val2) Here: val1 ==> real value ==> +eve/-eve val2 ==> imaginary value ==> +eve/-eve op = val1 +/- val2j Rules: ==== 1) any base value of an integer is considered as real data and imaginary data also. 2) float ==> complex 3) boolean ==> complex 4) string with decimal and string with floats ==> complex Note: ==== if complex(par1,par2): par1 ==> string par2 ==> not accepted. # a = 23-0b110j print(complex(0b1101)) print(complex(0b11001,0x1122)) print(complex(11.223)) print(complex(11.22,-22.34)) print(complex(True)) print(complex(True,False)) print(complex(False)) print(complex('1122')) # print(complex('1122',9.123)) print(complex('0.997789')) # print(complex('0b11001')) =========================================== bool() ===== ==> used to convert any data into boolean Syntax: bool(any value) print(bool(0)) print(bool(1)) print(bool(10)) print(bool(-10)) print(bool(0.0)) print(bool(0.000001)) print(bool(0+0j)) print(bool(0-0j)) print(bool(1-0j)) print(bool('')) print(bool(' ')) print(bool('a')) ===================================== 5) str() ===== ==> used to convert any data into string data. Syntax: str(any value) print(str(0b11001)) print(str(0o1122)) print(str(0x1122)) print(str(112233)) print(str(12e-23)) print(str(11.00043)) print(str(11-23j)) print(str(True)) print(str(False))