+ 3

how to capitalize the first 2 characters of any string??

"hello world!" as "HEllo world"

1st Oct 2019, 2:26 AM
Harsh Saxena
Harsh Saxena - avatar
6 odpowiedzi
+ 9
print((lambda st=input(): st[:2].upper() + st[2:])())
1st Oct 2019, 4:37 AM
Trigger
Trigger - avatar
+ 4
Please specify the language in Relevant Tags 👍 (Edit) Python language mentioned in Tags
1st Oct 2019, 2:43 AM
Ipang
+ 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))
1st Oct 2019, 3:36 AM
Ipang
1st Oct 2019, 3:10 AM
Harsh Saxena
Harsh Saxena - avatar
+ 3
This works lpang made the first part, I tweaked it and then redid my own: https://code.sololearn.com/cypKHuiXb1Io/?ref=app
1st Oct 2019, 3:47 AM
Bryan Souza
Bryan Souza - avatar
0
String Capitilized = myString.substring(0,2).ToUpper()+myString.substring(2,myString.length()-1)
2nd Oct 2019, 11:17 PM
Siyanda Cele
Siyanda Cele - avatar