Datatypes: ========== Primitive Datatypes: ==================== Integer Data Representation: ============================= Decimal Form ==> no prefix/suffix need to define Binary Form ==> 0b/0B Octal Form ==> 0o/0O Hexadecimal Form ==> 0x/0X Floating-Point Data Representation: ==================================== ==> number with decimal point ex: 0.00001, 123.213 etc. ==> Built-in Datatype pre-defined class ==> 'float' Note: ==== binary, octal and hexadecimal data notations not allowed for the floating-point data representation. ==> alternative definition for the floating-point: Scientific form/Exponent format ex: 1e7, 9e-7 etc. 1e7 ==> 1 X 10^7 ==> 0.1 X 10^8 9e-7 ==> 9 X 10^-7 ==> 0.9 X 10^-6 from email.encoders import encode_7or8bit a = 1.23 b = 0.001 # c = 0b11001.001 # c = 0O123.321 # d = 0X123.321 c = 1e7 d = 9E-7 print(a,type(a)) print(b,type(b)) print(c,type(c)) print(d,type(d)) ============================================ Complex Data Representation: ============================ ==> combination of real data and imaginary data ex: 2-3i or 2 + 3i etc. (Mathematically) Syntax: real-data +/- imaginary-data Here: real-data ==> decimal (int/float)/binary/octal/hexa-decimal imaginary-data ==> suffix with 'j' ex: bj ==> only decimal (float/int) ex: 123-123j, 12.23+23.34j, 0b110011-12j, 0o123+2.3j etc. ==> Built-in datatype pre-defined class ==> "complex". a = 123-321j b = 1.23+0.00097j c = 0b11001-12j d = 0O176+1.2j e = 0X1122-123j # f = 12-0b11001j print(a,type(a)) print(b,type(b)) print(c,type(c)) print(d,type(d)) print(e,type(e)) ================================================ Non-Numerical Datatype: ======================= True/False Boolean Data: ============= ==> Built-in datatype pre-defined class ==> "bool" two values: True False ex: a = True b = False Note: ===== True ==> 1 False ==> 0 a = True b = False print(a,type(a)) print(b,type(b)) print(True + True) # 1 + 1 print(True * True) # 1 * 1 print(True + False) print(True / False) ======================================= Collection Datatypes: ===================== Loan using any banking application: =================================== Job Details: ============ Package ==> 11.5 LPA Designation ==> Developer Location ==> Bangalore Address: Vizag Loan Type:Personal Amount:40000000 Loan = {11.5, Developer, Bangalore, Vizag, Personal, 40000000} ==> Can classified into several types: 1) Text Based 2) Sequential Based 3) Mapping Based 4) Set Based 5) Bytes Based Text Based Datatype: ==================== String Data Representation: ============================ String: group of characters which must be enclosed with either single quotes or double quotes. ex: 'python', "AshokIT", 'A', "R", "BR" etc. ==> built-in datatype pre-defined class ==> str Multi-line String: ================== triple quotes Syntax: """ multi-line string """ a = 'python' b = "Ashok IT" c = "1234" d = "@#$%^" e = 'AshokIT@1122' f = 's' g = "p" h = """ This is the Python Free Class from Ashok IT we can provide both material class and video access to you. Class notes and Videos can upload in Portal. """ i = "This is Ravi's class." j = 'Python Fullstack useful in various fields like: "Datascience", "Web Development", "Automation Testing"' k = 'Python is \'high-level\' programming language' l = "Python is \"Object-Oriented\" Programming Langauge" print(a,type(a)) print(b,type(b)) print(c,type(c)) print(d,type(d)) print(e,type(e)) print(type(f)) print(type(g)) print(h,type(h)) print(i) print(j) print(k) print(l) =========================================== Accessing of Individual Characters of the string: ================================================= Indexing ======== Accessing/Acquiring the character of the string based on the index is called as "Indexing". Index ==> Number we can define with +eve numbers ==> Positive Indexing and also with -eve numbers ==> Negative Indexing. Positive Indexing/Forward Indexing: =================================== ==> helps to access the characters of the string in forward access (left to right) ==> Positive Indexing can start with: Index '0' and end with 'length-string - 1'. ex: string with 10 characters +eve indexing ==> 0 to 9 (range) s = "Python" # index-0 ==> P, 1 ==> y, 2 => t, 3 => h, 4 ==> o, 5 ==> n print(s[0]) print(s[1]) print(s[2]) print(s[3]) print(s[4]) print(s[5]) # print(s[6]) Negative Indexing/reverse Indexing ================================== ==> helps to access the characters of the string from right to left (Reverse Accessing). ==> with negative index values ==> -1 to -length-string ex: string with 10 characters range of negative index ==> -1 to -10 s = "Python" print(s[-1]) print(s[-2]) print(s[-3]) print(s[-4]) print(s[-5]) print(s[-6])