DATATYPES =========== NON-SEQUENTIAL DATATYPES ========================== ==> NOT INDEX BASED ==> MAY OR MAY NOT BE ORDERED. ==> CLASSIFIED INTO: 1) SET DATATYPES 2) MAP DATATYPES 3) BYTE DATATYPES 1) SET DATATYPES ================ ==> THERE ARE TWO TYPES: 1) SETS 2) FROZENSETS 1) SETS ======= ==> ALWAYS BE DEFINED WITH {} SET ELEMENTS/ITEMS IN {} MUST BE SEPARATED WITH COMMA EX: {1,2,3,4,5,5} ==> PRE-DEFINED/INBUILT DATATYPE PRE-DEFINED CLASS ==> set FEATURES OF SET DATA: ===================== 1) SET IS HOMOGENEOUS. 2) SET IS HETEROGENEOUS. 3) SET CANNOT BE INCLUDE A LIST AS MEMBER. NOTE: if a set with list as a member ==> Type Error. 4) SET IS NOT AN ORDERED. 5) SET IS NOT INDEXED. Note: if an index is used to set for accessing individual elementes ==> Type Error. 6) NO SLICING IS ALLOWED ON SETS. 7) MUTABLE a = {1,2,3,4,5,6,7,8,9,10} # SET WITH INTEGERS => HOMOGENEOUS SET DATA b = {111,0.0097, True, 12-23j, 'abcde',(1,2,3,4,5,6)} # set with different types ==> heterogeneous data print(type(a)) print(type(b)) print(a) print(b) # print(a[0]) print(a) print(id(a)) # to modify the set definition, the index is not supported # with pre-defined method # add() a.add(100) print(a) print(id(a)) ================================================= FROZENSET ========== ==> similar to sets ==> is always be allowed to define with "frozenset()" ==> forzenset() ==> pre-defined method, which we can use to convert any collection to frozenset. Syntax: frozenset(collection data) ==> it is an inbuilt datatype class ==> frozenset Features - Frozenset ================= 1) Homogeenous 2) Heterogeneous 3) Not Ordered 4) Not indexed 5) no slicing is possible 6) immutable. a = "Python" b = [1,3,5,7,9,11] c = (2,4,6,8,10) d = {1,2,3,4,5,6,7,8,9,11,13,15} e = ['a',11,True, 12-23j,11.123] print(type(a),type(b),type(c),type(d)) p = frozenset(a) q = frozenset(b) r = frozenset(c) s = frozenset(d) t = frozenset(e) print(type(p),type(q),type(r),type(s),type(t)) print(p) print(q) print(r) print(s) print(t) # print(p[0]) # p.add(100) ============================================================================ 2) MAP DATATYPES ================ ==> can always be defined with key and value pair format. key : value ==> There is only one map datatype: Dictionary Dictionary Datatype: ===============- ==> can be defined with {}, here the elements are in the "key-value" pair format key : value ==> the key-value pair is an element/item/member of the dictionary ==> these members must be placed within {} using the comma separation. ==> Inbuilt datatype pre-defined class: dict Features of Dictionary: =================== about keys: ========= 1) keys are with any datatype 2) keys must be unique about values: ========== 1|) values are with any datatype 2) values not to be unique. 1) Homogeenous 2) Heterogeneous 3) Is an Ordered. 4) Not an index supported. Note: if an index is used to access the dictionary elements ==> Key Error. 5) Dictionary values can be accessed with its corresponding keys. Syntax: dictionary_name[key name] 6) Mutable a = {'key1' : 111,'key2' : 222,'key3' : 333} b = {'a' : 11,True : 11.123, 1-2j : False} print(type(a)) print(type(b)) print(a) print(b) # print(a[0]) print(a['key2']) print(b[True]) print(id(a)) a['key2'] = 2222 print(a) print(id(a)) ================================================== 3) Byte Type =========== ==> there are two types: 1) bytes 2) bytearray Note: ==== 1 byte ==> 8-bits 2^8 ==> 256 characters 0 to 255 ==> bytes and bytearray data can be always allowed to define with values from 0 to 255 only. 1) bytes ======= ==> can always be defined with bytes() ==> bytes() can allow any collection to convert into bytes. Synyax: bytes(collection data) ==> Pre-defined datatype Predefined class ==> bytes Features of Bytes Data: =================== 1) Homogeneous only. 2) Oredered. 3) Index based. 4) Slicing is allowed. 5) Immutable. # a = 'abcdef' b = [11,13,15,17,19] c = (10,20,30,40,50) d = {1,3,5,7,9} e = {11:10,21:11,31:12,41:13,51:14,61:15} print(type(b),type(c),type(d),type(e)) # p = btyes(a) q = bytes(b) r = bytes(c) s = bytes(d) t = bytes(e) print(type(q),type(r),type(s),type(t)) print(q) print(q[0]) print(q[-1]) print(q[::-1]) print(r[::-2]) print(id(q)) # q[0] = 101 ===================================== 2) bytearray ========== a = bytearray([10,20,30,40,50,60]) b = bytearray((11,21,31,41,51,30)) print(type(a),type(b)) print(a) print(b) print(a[0]) print(b[::-1]) print(id(a)) a[0] = 100 print(a) print(id(a))