+ 3
how to capitalize the first 2 characters of any string??
"hello world!" as "HEllo world"
6 odpowiedzi
+ 9
print((lambda st=input(): st[:2].upper() + st[2:])())
+ 4
Please specify the language in Relevant Tags 👍
(Edit)
Python language mentioned in Tags
+ 4
This may work, just pass the string and how many characters to capitalize to the function
def capitalize_first(s, p):
if len(s) == 0: return s
if p not in range(1, len(s)):
return s.upper()
return s[:p].upper() + s[p:]
# test drive
s = "sololearn"
for i in range(1, 12):
print(i, capitalize_first(s, i))
+ 3
+ 3
This works
lpang made the first part, I tweaked it and then redid my own:
https://code.sololearn.com/cypKHuiXb1Io/?ref=app
0
String Capitilized = myString.substring(0,2).ToUpper()+myString.substring(2,myString.length()-1)