How to convert part of a string to uppercase start from specific index in Python

1 Answer

0 votes
def convert_part_to_uppercase(s, idx) : 
    length = len(s) 
    if (idx < 0 or idx > length): return s
    s = list(s)
  
    for i in range(length) : 
        if (i >= idx and (ord(s[i]) >= 97 and ord(s[i]) <= 122)):
            s[i] = chr(ord(s[i]) - 32)
     
    return "".join(s)
   
   
   
s = "python programming"
       
s = convert_part_to_uppercase(s, 4)
print(s)
       

 
 
'''
run:
 
pythON PROGRAMMING
 
'''

 



answered Nov 16, 2019 by avibootz
...