# WAP IN PYTHON TO DISPLAY ALL POSITIONS OF SUBSTRING IN THE GIVEN STRING. str_data = input("Enter a string data:") subs = input("Enter a sub-string:") """ find the sub-string from 0 to till last character ==> iteration we need to continue of find the sub-string even after identified at place we need to continue to search about the sub-string if it is not at first character find() ==> -1, when the sub-string is not match in the given string index() ==> value error, when the sub-string is not match in the given string """ flag = False length = len(str_data) pos = -1 while True: pos = str_data.find(subs,pos+1,length) if pos == -1: break print("The Sub-string is found at:",pos) flag = True if flag == False: print("The Sub-string is not found at any index.") ================================================= replacing of a string with another string ============================== "Python is Very Difficult to learn" "Difficult" ===> "Easy" "Python is Very Easy to learn" replace() ======= Syntax: str_data/str_object.replace('old_string','new_string') str_data = "Python is Very Difficult to Learn" sub_str = "Easy" res_str = str_data.replace('Difficult',sub_str) print(str_data) print(res_str) =========================================== Python is Unicode Dependent Programming Language ========================================== C/C++ ==> characters ==> 256 characters ASCII Values ==> 0 to 255 Java/Python ==> 2-bytes 65536 characters 0 to 65535 ==> Unicode 0 TO 9 ==> 48 TO 56 A TO Z ==> 65 TO 90 a to z ==> 97 to 122 ord() ==== ==> which can accept a character return a unicode of the accepted character's Syntax: ord(character) print(ord('A')) print(ord('b')) print(ord("r")) print(ord('9')) print(ord('@')) =================================== chr() === ==> pre-defined method which can access a unicode value and return the corresponding character value Syntax: chr(unicode) print(chr(65535)) print(chr(0)) print(chr(100)) print(chr(1000)) for i in range(65536): print("The Character at the Unicode {} is = {}".format(i,chr(i))) ======================================================== STRING TO LIST ============= split() ==== Syntax: str_data.split('seperator') Ex: "Python Programming Language" seperator ==> space ['Python','Programming','Language'] s1 = "Python Programming Language" s2 = "Python" s3 = "07-08-2024" s4 = "07/08/2024" s5 = "07.08.2024" r1 = s1.split(' ') r2 = s1.split() r3 = s2.split('h') r4 = s3.split('-') r5 = s4.split("/") r6 = s5.split('.') print(r1) print(r2) print(r3) print(r4) print(r5) print(r6) ==================================================== LIST TO STRING ============= join() ==== used to join the individual elements of the list into string based on the separator. Syntax: 'separator'.join(list_data) l1 = ['Python','is','easy','language'] l2 = ['08','07','2024'] s1 = ' '.join(l1) s2 = '-'.join(l2) s3 = '/'.join(l2) s4 = '.'.join(l2) print(s1) print(s2) print(s3) print(s4)