STRING OPERATIONS ================= TRAVERSING ON STRING DATA: ========================== CAN POSSIBLE WITH LOOPS 1) USING WHILE LOOP: ==================== Syntax: initialization with index while condition: operation update # WAP TO PRINT ALL THE INDIVIDUAL CHARACTERS OF THE GIVEN STRING ALONG WITH BOTH POSITIVE AND NEGATIVE INDEX. """ The Character at Positive Index 0 and at Negative Index -7 is = a """ # defining of string in run time s1 = input("Enter a string data:") # s1 = str(input("Enter a string data:")) # s1 = "Python" length = len(s1) # forward accessing index = 0 while index < length: print("The Character at positive index {} and at negative index {} is = {}".format(index,index-length,s1[index])) index = index + 1 print() # reverse accessing i = -1 while i >= -length: print("The Character at negative index {} and at positive index {} is = {}".format(i,i+length,s1[i])) i = i - 1 ============================================ Using for loop: ============== Syntax: for iteration_variable in str-data: block of operation eval() ====== is an inbuilt method, which we can use to define any collection data in run time (with dynamically change). Syntax: str-object = eval(input("Enter something:")) # WAP TO PRINT THE CHARACTERS OF THE STRING ALONG WITH POSITIVE AND NEGATIVE INDEX VALUES. s = eval(input("Enter a string data:")) # forward accessing index = 0 for ind in s: print("The Character at positive index {} and at negative index {} is = {}".format(index,index-len(s),ind)) index += 1 print() # reverse accessing i1 = -1 for i in s[::-1]: print("The Character at negative index {} and at positive index {} is = {}".format(i1,i1 + len(s),i)) i1 -= 1 ========================================= # WAP TO FIND THE LENGTH OF THE STRING WITHOUT PRE-DEFINED METHOD s1 = input("Enter a string data:") count = 0 for ind in s1: count += 1 print("The Length of the string is = ",count) ========================================= CASE CHANGE OPERATIONS: ======================= LOWER CASE ==> UPPER CASE UPPER CASE ==> LOWER CASE lower() ====== ==> an inbuilt method which we can use to convert the string into lower case string. Syntax: str-data.lower() upper() ======= ==> an inbuilt method which we can use to convert any string into upper case. Syntax: str-data.upper() capitalize() ============ Capitalize case ==> the total string with lower case characters except the first character. capitalize() is an inbuilt method which we can use to change the string into capitalize case. Syntax: str-data.capitalize() swpacase() ========= is an inbuilt method which we can use to convert lower case to upper case and vice versa. Syntax: str-data.swapcase() title() ======= title case ==> when the string with more than one word ex: python programming that every word's first character should be in capital and remaining in lower case. Python Programming title() is an inbuilt method which we can use to change the string to title case string. Syntax: str-data.title() # Case Change s1 = eval(input("Enter a string data:")) print("The Original String is = ",s1) print("The String in Lower case is = ",s1.lower()) print("The String in Upper case is = ",s1.upper()) print("The Swap case String is = ",s1.swapcase()) print("The String in Capitalize case is = ",s1.capitalize()) print("The String in Title case is = ",s1.title()) ===================================================