Lowercase in Python

+5 votes

How can you convert a string to lowercase or upper case?
For example, I want to convert the below string in upper case. What should I do?

s= "Python is best"
Apr 11, 2018 in Python by ana1504.k
• 7,910 points

retagged Oct 12, 2018 by Priyaj 4,122 views

6 answers to this question.

+3 votes
Best answer
You can simply the built-in function in python: lower() and upper()
Fr example:
s="Python is best"
print(s.upper())
print(s.lower())

Output:

PYTHON IS BEST
python is best
answered Apr 11, 2018 by hemant
• 5,790 points

selected Oct 12, 2018 by Omkar
+1 vote
s = "Kilometer"
print(s.lower())

The official documentation is str.lower().

answered Oct 12, 2018 by findingbugs
• 4,780 points
+1 vote

With Python 2, this doesn't work for non-English words in UTF-8. In this case decode('utf-8') can help:

>>> s='ALpHabet'
>>> print s.lower()
alphabet
>>> print s.decode('utf-8').lower()
alphabet
answered Oct 12, 2018 by abc
+1 vote

The canonical Pythonic way of doing this is

>>> 'Kilometers'.lower()
'kilometers'

However, if the purpose is to do case insensitive matching, you should use case-folding:

>>> 'Kilometers'.casefold()
'kilometers'

Here's why:

>>> "Maße".casefold()
'masse'
>>> "Maße".lower()
'maße'
>>> "MASSE" == "Maße"
False
>>> "MASSE".lower() == "Maße".lower()
False
>>> "MASSE".casefold() == "Maße".casefold()
True
answered Oct 12, 2018 by rani
+1 vote

if you want the user to input something you could do the below code:

raw_input('Type Something').lower()

It will then automatically convert the string they typed into lowercase.

Note: raw_input was renamed to input in Python 3.x and above.

answered Oct 12, 2018 by kalpesh
+1 vote
s = input('UPPER CASE')
lower = s.lower()

If you use like this:

s = "Kilometer"
print(s.lower())     - kilometer
print(s)             - Kilometer

It will work just when called.

answered Oct 12, 2018 by Trisha

Related Questions In Python

+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,890 points
20,075 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
1,336 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
4,934 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
6,476 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
13,581 views
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
15,325 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP