How to convert a word in uppercase and lowercase in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to convert a word in uppercase and lowercase in python

Given a word HelLo, Condition :- for start two characters is lower case and remains three is uppercase Output:-heLLO

27th Jan 2020, 5:49 PM
Mohit Kumawat
Mohit Kumawat - avatar
2 Answers
+ 9
You can use type str's builtin methods upper() and lower() in combination with slicing the original string and glueing it back together.
27th Jan 2020, 5:52 PM
HonFu
HonFu - avatar
0
You can use splice and .upper() for uppercase and .lower() for lowercase characters. So, your code can be: word = "Hello" print(word[:2].lower() + word[2:].upper())
28th Jan 2020, 1:38 AM
Sakar12321_12